Quick background: I'm working on an application to upload some csv data to a third party vendor. We have an AWS S3 bucket that watches for file uploads and the triggers a Lambda. The lambda then runs our kotlin code. The code downloads the newly arrived file from the bucket, builds a config file, and then executes a jar file (supplied by the vendor) which is responsible for actually sending the file along to it's final destination.
It is that last step that I am struggling with. What is the kotlin syntax for calling an executable jar? Is this even possible? If not, what alternative options are there?
For reference, here is the 'pipeline' function being called by the lambda:
fun pipeline(inputStream: java.io.InputStream, dp: INT295DependencyProvider): Either<Throwable,String> {
val j = dp.journalFactory("app.eventmanagement.pipeline")
val input = IOUtils.toString(inputStream, Charset.defaultCharset())
j.debug(input)
return dp.json.value().fromJson<S3EventNotification.S3Event>(input).fold({
j.error("Error extracting key: " + it.message)
it.left()
},{
event->
j.debug("getting key from event: $event")
val key = event.let { it.records?.firstOrNull()?.s3?.s3object?.key }
j.debug("key: $key")
if(key != null)
{
//Download the csv file from the S3 bucket
val badgeFile: File = createTempFile(suffix = ".csv").toFile()
badgeFile.copyInputStreamToFile( s3ReadObjectFromBucket(dp.bucket.value(), key, dp.s3.value()) )
//build a config file for the jar
val configFile = buildPropertiesFile(dp, "config",
TsProperties(dp.baseUrl.value(), dp.appId.value(), dp.tsSecret.value(), dp.badgingKey.value()))
//execute the jar to send the downloaded csv file to the vendor
//java -jar badgeupload-2.0.jar --config config --badgesCsv badges
"passed".right()
}
else
{
Throwable("Key not found").left()
}
})
}