Book Image

Amazon S3 Cookbook (n)

By : Naoya Hashimoto
Book Image

Amazon S3 Cookbook (n)

By: Naoya Hashimoto

Overview of this book

Table of Contents (19 chapters)
Amazon S3 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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
    $ cat> ${cors} <<EOF
    {
        "CORSRules": [
            {
                "AllowedHeaders": [
                    "Authorization"
                ],
                "MaxAgeSeconds": 3000,
                "AllowedMethods": [
                    "GET"
                ],
     ...