Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Bucket Object Lifecycle support #6141

Open
franciscocpg opened this issue May 15, 2019 · 5 comments
Open

S3 Bucket Object Lifecycle support #6141

franciscocpg opened this issue May 15, 2019 · 5 comments

Comments

@franciscocpg
Copy link
Contributor

This is a Feature Proposal

Description

I want to configure lifecycle for a bucket created by s3 event (like #3308).

I read custom bucket configuration but since my bucket name is dynamic (eg: ${self:provider.stage}-my-bucket) I'm not sure how to follow the logical IDs rules explained there.

So, is there a way to have a bucket created by s3 event AND configure a lifecyle for it?

Similar or dependent issues:

@herebebogans
Copy link
Contributor

herebebogans commented May 16, 2019

@franciscocpg

Try this config for an event on upload of a *.gz file to a cloudformation customised s3 bucket.

You could make the bucketname a serverless variable to DRY it up a bit.

....
....

functions:
  myfunction:
    handler: handler.createEvent                      
    events:
      - s3:
          bucket: example
          event: s3:ObjectCreated:*
          rules:
            - suffix: .gz
...
...
                      
resources:
  Description: My S3 Event Stack
  Resources:
    S3BucketExample:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:provider.stage}-my-example-bucket
        LifecycleConfiguration:
          Rules:
            -
              ExpirationInDays: 7
              Prefix: '/'
              Status: Enabled 
                       
    MyfunctionLambdaPermissionExampleS3:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName: !GetAtt MyfunctionLambdaFunction.Arn
        Principal: s3.amazonaws.com
        Action: lambda:InvokeFunction
        SourceAccount:
          Ref: AWS::AccountId
        SourceArn: arn:aws:s3:::${self:provider.stage}-my-example-bucket

@phirapara
Copy link

How can we add lifecycle configuration for existing s3 bucket. It is not allowing for existing s3 bucket.

@pgrzesik
Copy link
Contributor

@phirapara Hello, what are you trying to achieve? Use existing backed as event trigger or you want to adjust it's lifecycle configuration?

@phirapara
Copy link

@pgrzesik, Thanks for responding.

I am using existing as bucket trigger(as shown below) which works fine , and I want to add lifecycle policy to that existing bucket.

functions:
 myFunction:
    handler: imageProcessor
   events:
     - s3:
         bucket: ExistingBucket
         rules:
           - prefix: images/
         existing: true

I tried to configure it under resources, but it does not allow to use exiting resource

@pgrzesik
Copy link
Contributor

You might want to try with importing resources into the CloudFormation stack, but I think it might be a bit challenging to actually achieve. Your best bet would be to either configure it separately from the Framework or use a newly created bucket that is fully managed by underlying CloudFormation stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants