Create s3 events with a lifecycle policy


I’ve been trying to implement a serverless.yml for an S3 bucket, which triggers a lambda function, and then deletes the objects after a week.

serverless.yml gist

So i’m defining the s3 event under the functions, which creates an S3 bucket, then under Resources i define the same s3 bucket with the lifecycle policy. And i get the following error:

An error occurred: S3BucketBucket1mediaupload - bucket-1 already exists in stack arn:aws:cloudformation:us-east-1:**********:stack/my-service-prod/

Is my best bet to define the whole bucket (s3 event and lifecycle policy, link to lambda) in the Resources?

Thanks so much :slight_smile:

If anyone has trouble with this, i realised there is an s3 event tag “existing: true” which I’ve added, and thus it doesn’t break when adding lifecycle rules in the Resources section.