Walkthrough 2: Enabling CORS with AWS CLI

This section is almost same as walkthrough 1. The difference is that we only use AWS CLI to enable S3 CORS because it is much more simple than operating through S3 console.

Getting ready

You do not have to request permissions to enable S3 CORS. All you need to do is:

  • Sign up on AWS and be able to access S3 with your IAM credentials
  • Launch an EC2 instance and start the web server
  • Install and set up AWS CLI on your PC or use Amazon Linux AMI

How to do it…

To enable CORS with AWS CLI, you just need to create a CORS configuration in the JSON format and use the aws s3api command to configure the CORS configuration for your bucket. Let's get started with AWS CLI:

  1. Create a CORS configuration file:
    $ cors=cors_file.json ...

Get Amazon S3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.