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

Missing support for CORS in S3 Bucket properties #2101

Closed
barroij opened this issue Mar 27, 2019 · 2 comments
Closed

Missing support for CORS in S3 Bucket properties #2101

barroij opened this issue Mar 27, 2019 · 2 comments
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved. guidance Question that needs advice or information.

Comments

@barroij
Copy link

barroij commented Mar 27, 2019

I cannot use the provided Bucket construct if I want to enable CORS on my bucket as there is no way to pass it to the underlying CfnBucket.

And I'm not aware of techniques that would prevent me to add this without copy-pasting the whole Bucket class to just modify the constructor.

(
By the way, in order to enable easier customisation, it might worth writing provided constructs like this :

export class Bucket extends BucketBase {
  constructor(scope: cdk.Construct, id: string, props: BucketProps = {}) {
    super(scope, id);
    this.construct(props)
  }
private  construct(props: BucketProps ) {
// construction code here
const resource = new CfnBucket(this, 'Resource', {...
}
}

So that if I want to customize how the CfnXXX resource is built from my params, I can just extends the Bucket class, overwrite only the construct method, and profit from the rest of the implementation, instead of duplicating the whole class
)

@barroij
Copy link
Author

barroij commented Mar 27, 2019

For those interested, I might have found a workaround for that :

    this.bucket = new s3.Bucket(this, props.s3BucketName)
    const cfnBucket = this.bucket.node.findChild('Resource') as s3.CfnBucket
    cfnBucket.addPropertyOverride('CorsConfiguration', {
      CorsRules: [
        {
          AllowedOrigins: ['*'],
          AllowedMethods: ['HEAD', 'GET', 'PUT', 'POST', 'DELETE'],
          MaxAge: '3000',
          ExposedHeaders: [
            'x-amz-server-side-encryption',
            'x-amz-request-id',
            'x-amz-id-2',
            'ETag'
          ],
          AllowedHeaders: ['*']
        }
      ]
    })

workeitel added a commit to workeitel/aws-cdk that referenced this issue Jun 12, 2019
Add CORS Property to S3 Bucket for configuring bucket cross-origin
access rules.

You can either specify the metrics as properties:

     new Bucket(stack, 'Bucket', {
       cors: [
         {
           allowedHeaders: [
             "*"
           ],
           allowedMethods: [
             "GET"
           ],
           allowedOrigins: [
             "*"
           ],
           exposedHeaders: [
             "Date"
           ],
           id: "myCORSRuleId1",
           maxAge: 3600
         }
       ]
     });

Or use the `addCors` function:

    const bucket = new Bucket(stack, 'Bucket');
    bucket.addCors({
      allowedMethods: ["GET", "HEAD"],
      allowedOrigins: ["https://example.com"]
    });
workeitel added a commit to workeitel/aws-cdk that referenced this issue Jun 12, 2019
Add CORS Property to S3 Bucket for configuring bucket cross-origin
access rules.

You can either specify the metrics as properties:

     new Bucket(stack, 'Bucket', {
       cors: [
         {
           allowedHeaders: [
             "*"
           ],
           allowedMethods: [
             "GET"
           ],
           allowedOrigins: [
             "*"
           ],
           exposedHeaders: [
             "Date"
           ],
           id: "myCORSRuleId1",
           maxAge: 3600
         }
       ]
     });

Or use the `addCors` function:

    const bucket = new Bucket(stack, 'Bucket');
    bucket.addCors({
      allowedMethods: ["GET", "HEAD"],
      allowedOrigins: ["https://example.com"]
    });
workeitel added a commit to workeitel/aws-cdk that referenced this issue Jun 13, 2019
Add CORS Property to S3 Bucket for configuring bucket cross-origin
access rules.

You can either specify the metrics as properties:

     new Bucket(stack, 'Bucket', {
       cors: [
         {
           allowedHeaders: [
             "*"
           ],
           allowedMethods: [
             "GET"
           ],
           allowedOrigins: [
             "*"
           ],
           exposedHeaders: [
             "Date"
           ],
           id: "myCORSRuleId1",
           maxAge: 3600
         }
       ]
     });

Or use the `addCors` function:

    const bucket = new Bucket(stack, 'Bucket');
    bucket.addCors({
      allowedMethods: ["GET", "HEAD"],
      allowedOrigins: ["https://example.com"]
    });
rix0rrr pushed a commit that referenced this issue Jun 17, 2019
Add CORS Property to S3 Bucket for configuring bucket cross-origin
access rules.
@SomayaB SomayaB self-assigned this Sep 7, 2019
@SomayaB SomayaB added needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-s3 Related to Amazon S3 guidance Question that needs advice or information. labels Sep 7, 2019
@SomayaB SomayaB added feature-request A feature should be added or improved. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2019
@SomayaB
Copy link
Contributor

SomayaB commented Sep 17, 2019

This should be closed by #2843. Let me know if this isn't the case. Closing now, please reopen if this is still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants