Running Spring Batch application using AWS Batch
343
How to trigger AWS Batch on S3 upload event & pass S3 BucketName and FileName(key) to the Spring Batch application
Following steps describe how to send S3 source Event MetaData (Bucket Name and File Name) as arguments to a Spring Batch application.
Event Source Section:Remove key tag and its value completely from the Event Pattern of the batch Cloudwatch Rule. Add key tag in case you need to trigger event only when a file with specific name key is uploaded to the specified S3 bucket.
{
"source": [
"aws.s3"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"s3.amazonaws.com"
],
"eventName": [
"PutObject",
"CompleteMultipartUpload",
"CopyObject"
],
"requestParameters": {
"bucketName": [
"<WRITE_NAME_OF_YOUR_BUCKET>"
]
}
}
}
Target SectionChoose Input Transformer option under Configure Input section:
{"S3KeyValue":"$.detail.requestParameters.key","S3BucketValue":"$.detail.requestParameters.bucketName"}{"Parameters" : {"S3bucket": <S3BucketValue>, "S3key": <S3KeyValue>}}Job DefinitionAdd the following to Environment -> Command -> Space Delimited text box:
Ref::S3bucket Ref::S3keyThe values specified for S3bucket and S3key will be available to the Spring Batch application in args[] argument of main() method-
@SpringBootApplication
public class BatchProcessingApplication {
public static void main(String[] args) throws Exception {
System.out.println("args:");
for (String arg : args) {
System.out.println(arg); // This will print the S3bucket and S3key argument values
}
SpringApplication.run(BatchProcessingApplication.class, args);
}
}
Content type
Image
Digest
Size
247 MB
Last updated
about 6 years ago
docker pull kunupat/springboot-batch-example