I am trying to write a cloudformation template which involves adding an event to a bucket to trigger a lambda function.
I know i can use code such as the below to create a bucket and an event at the same time but my bucket already exists and i don't want another one so is there a way of creating an event for an existing bucket within cloud formation?
"EncryptionServiceBucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"BucketName" : { "Fn::Sub" : "${User}-encryption-service" },
"NotificationConfiguration" : {
"LambdaConfigurations" : [{
"Function" : { "Ref" : "LambdaDeploymentArn" },
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : [{
"Name" : "suffix",
"Value" : "zip"
}]
}
}
}]
}
}
}
Sign in to the AWS Management Console, open the AWS CloudFormation console, choose View stack, choose Create stack, and then choose With existing resources (import resources). Choose Upload a template file and then upload the template file that you created earlier.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to enable events for. Choose Properties. Navigate to the Event Notifications section and choose Create event notification.
I have not found a way to manage existing resources with CloudFormation. Also, using the BucketName
property on a bucket limits CloudFormation's ability to manage your bucket significantly. For example, it cannot replace the resource, or create it again in another stack in your account. I suggest instead to leave out this property, let Cloudformation create bucket names and reference the bucket's ARNs in your with via environment variables set in the same stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With