Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudformation Trigger Event for Existing bucket

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"
            }]
          }
        }
      }]
    }
  }
}
like image 913
SamBremner Avatar asked May 10 '18 16:05

SamBremner


People also ask

How do I use an existing S3 bucket in CloudFormation?

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.

How can you send notification every time a new file is created in AWS S3?

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.


1 Answers

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.

like image 84
kino1 Avatar answered Oct 14 '22 23:10

kino1