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

Allow CORS/Configuration of bucket created by S3 event #2749

Closed
jeffski opened this issue Nov 20, 2016 · 12 comments
Closed

Allow CORS/Configuration of bucket created by S3 event #2749

jeffski opened this issue Nov 20, 2016 · 12 comments

Comments

@jeffski
Copy link

@jeffski jeffski commented Nov 20, 2016

What is the use case that should be solved.

I'm using Serverless to create a service that processes user uploaded videos and uses a Lambda to queue them to Elastic Transcoder. I've got a function and an event like this:

functions:
  transcoder:
    handler: handler.transcoder
    events:
      - s3: myBucket
        event: s3:ObjectCreated:*

The problem is that files can't be uploaded because by default the bucket will not accept CORS requests, I've got a website hosted on S3 that is doing the uploads.

I have tried to add a resource for the bucket and add CORS configuration but get an error because the bucket has already been created by the previous events setup.

I think this will be a reasonably common use case - handling user submitted uploads from a web site to S3 and users will get the CORS error.

I'd like to see either a way to configure/enable CORS on the event bucket or don't create the bucket and make that a task that has to be done in resources.

@jeffski
Copy link
Author

@jeffski jeffski commented Nov 20, 2016

Just to add - for now I've gone in to S3 in the web console and added the CORS rules.

@pmuens
Copy link
Contributor

@pmuens pmuens commented Nov 20, 2016

@jeffski Thanks for opening this! 👍

This could be a great config parameter for the extended bucket configuration. What do you think @eahefnawy

@jeffski
Copy link
Author

@jeffski jeffski commented Nov 25, 2016

I've run in to another problem to do with the automatic creation of buckets for events - basically if the bucket already exists then I am getting an error like bucket already exists in stack arn... - the bucket is created in another serverless.yml resource/cloud formation setup.

A way to disable the creation of the bucket might be good, or ignore if exists or users just create buckets manually via resources which should avoid this situation and allow CORS to be setup.

@kennu
Copy link
Contributor

@kennu kennu commented Mar 15, 2017

I also just ran into this issue now, trying to setup a public S3 upload bucket which needs CORS configuration (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-cors.html).

@obezuk
Copy link

@obezuk obezuk commented Mar 15, 2017

Just so this thread is aware, I'm also experiencing the same issue but it's been discussed in more detail in a related issue #2967.

@drazafsky
Copy link

@drazafsky drazafsky commented Apr 16, 2017

I've also run into this issue and it's proving to be a major hassle since it means adding an extra step outside of the Serverless deployment to any bucket that needs to have CORS configured. Really disappointed that the answer seems to be that it's just not going to be supported.

@wulftone
Copy link

@wulftone wulftone commented Jun 8, 2017

Any progress on this issue? It's a big roadblock in our serverless stack.

@pmuens
Copy link
Contributor

@pmuens pmuens commented Jun 9, 2017

Any progress on this issue? It's a big roadblock in our serverless stack.

@wulftone We've not worked on an implementation for that yet. I added the help-wanted label.

@esamattis
Copy link

@esamattis esamattis commented Apr 6, 2018

As a scripted workaround it is possible to upload cors configuration with aws cli:

aws s3api put-bucket-cors --bucket mybucket --cors-configuration file://s3-cors.json

s3-cors.json:

{
    "CORSRules": [
        {
            "AllowedOrigins": ["*"],
            "AllowedHeaders": ["*"],
            "AllowedMethods": ["PUT", "POST", "DELETE"],
            "MaxAgeSeconds": 3000
        },
        {
            "AllowedOrigins": ["*"],
            "AllowedHeaders": ["Authorization"],
            "AllowedMethods": ["GET"],
            "MaxAgeSeconds": 3000
        }
    ]
}
@xj42
Copy link

@xj42 xj42 commented Aug 15, 2019

this would be a huge help

@floydspace
Copy link

@floydspace floydspace commented Aug 22, 2019

functions:
transcoder:
handler: handler.transcoder
events:
- s3: myBucket
event: s3:ObjectCreated:*

you can add in addition to function configuration this:

resources:
  Resources:
    S3BucketMyBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: myBucket
        CorsConfiguration:
          CorsRules:
            -
              AllowedOrigins:
                - '*'
              AllowedHeaders:
                - '*'
              AllowedMethods:
                - PUT
              MaxAge: 3000
    TranscoderLambdaPermissionMyBucketS3:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName:
          Fn::GetAtt:
            - TranscoderLambdaFunction
            - Arn
        Action: lambda:InvokeFunction
        Principal: s3.amazonaws.com
        SourceAccount:
          Ref: AWS::AccountId
        SourceArn: arn:aws:s3:::myBucket

and it should work.

see Custom bucket configuration

@medikoo
Copy link
Member

@medikoo medikoo commented Sep 7, 2020

Addressed with #7156

@medikoo medikoo closed this Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants