DEV Community

chrishart0 for Signet Seal

Posted on

4

Configure CORS for an S3 Bucket Using Python AWS CDK

Get right to it, here is the code

Python CDK code for configuring CORS on an S3 bucket.

bucket = s3.Bucket(self, "myBucket",
    cors=[
        s3.CorsRule(
            allowed_headers=[CORS_headers],
            allowed_methods=[s3.HttpMethods.PUT, s3.HttpMethods.POST, s3.HttpMethods.GET, s3.HttpMethods.DELETE],
            allowed_origins=[CORS_url]
        )
    ]
)
Enter fullscreen mode Exit fullscreen mode

A list of the HTTP methods which can be configured can be found here in the aws_cdk.aws_s3.HttpMethods docs

Relevant docs:

More CDK or AWS Serverless Questions?

Feel free to leave a comment here or hit us up on LinkedIn.

Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website SignetSeal.com

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay