I'm curious if we could create a trigger on a AWS S3 Bucket programmatically?
Given is a S3-Bucket and a AWS Lambda function. The AWS Lambda function was created per CLI and can be updated/recreated at any time with CLI-based commands.
aws lambda create-function \
--region us-east-1 \
--function-name encodeVideo \
--zip-file fileb:///tmp/encode_video.zip \
--role $LAMBDA_ROLE_ARN \
--handler encode_video.handler \
--runtime nodejs6.10 \
--timeout 10 \
--memory-size 1024
aws lambda add-permission \
--function-name encodeVideo \
--region us-east-1 \
--statement-id some-unique-id \
--action "lambda:InvokeFunction" \
--principal s3.amazonaws.com \
--source-arn arn:aws:s3:::**** \
--source-account ***********
Now i want to configure a S3-bucket that it will invoke the Lambda function automatically on every new object that was created.
For now i did this in AWS Console in web browser as one can see in the screenshot. But i want to be able to setup the whole scenario with CLI-commands. How can i do this?
I've figured out that it needs something like:
aws s3api put-bucket-notification-configuration --region us-east-1 \
--bucket **** \
--notification-configuration file://encodeVideoConfiguration.json
But i couldn't figure out what the content of encodeVideoConfiguration.json should be?
