Monitors the s3 buckets "upload" directory for new image files and triggers their processing by calling the step function.
- s3-archive-image.js - source code.
- Using the AWS IAM Console create an IAM Role containing the "AWSLambdaBasicExecutionRole" and "AmazonS3FullAccess" permissions.
- Using the AWS IAM Console you also need to manually add an inline policy to your new created IAM Role, giving permission to run Step Functions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"states:StartExecution"
],
"Resource": [
"*"
]
}
]
}The variable STEP_MACHINE_ARN needs to be declared and defined in the Lambda Function console. This should point to the ARN of your Step Function.
- Using the AWS Lambda Console, create a new Lambda Function, using the "blank function" blueprint.
- Create a trigger for your s3 bucket with the event type "Object Create (All)" and the prefix "upload/". This will ensure that this function is run for each new item uploaded to the "upload" directory of your s3 bucket.
- Once the trigger has been specified you can copy the code from s3-trigger-image-processing.js directly into the inline code editor.
- Ensure that the function uses your newly created IAM Role.