We are creating an S3 bucket using a CloudFormation template. I would like to associate (Add an event to S3 bucket) a Lambda function whenever a file is added to the S3 bucket.
Yes, it's possible through Cloudformation, and what you need to configure are:
1) AWS::S3::Bucket
resource and,
2) NotificationConfiguration
configuration (use LambdaConfigurations
in this case) for the s3 resource above.
Related documentation that you need:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-notification
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig.html