Configure S3 bucket to enable CORS configuration

Mohit Sethi
Appliedcode
Published in
1 min readMay 24, 2015

In order to configure s3 to allow cross-origin sharing, we need to create CORS configuration, xml document with rules that identify the origins that will allow to access your bucket, the operation(HTTP methods) will support for each origin according to configuration mentioned in S3.

In CORS configuration, you can specify following values for the AllowedMethod element.

  • GET
  • PUT
  • POST
  • DELETE
  • HEAD

While defining we must understand the following rules:

  • First we need to specify the AllowMethod (GET, PUT, DELETE Etc) request on the first origin . The rule also allows all headers in a preflight OPTIONS request through the Access-Control-Request-Headers header.
  • Same rules in applied on another origin
  • The third rule allows cross-origin GET requests from all origins. The ‘*’ wildcard character refers to all origins.

Configuring S3 bucket:

Within the properties of the bucket we have to choose the option “Edit CORS configuration”:

In the window that appears, enter a configuration like this:

This will accept any GET, PUT, POST or DELETE request for any element in the bucket, as long as the origin of the request is an element stored in a subdomain of example.com.

Technically, the bucket will respond to these requests with the header “Access-Control-Allow-Origin: *.example.com” when they are performed including the header Origin.

This way you can configure the s3 to enable the CORS configuration.

--

--

Mohit Sethi
Appliedcode

OpenSource | DevSecOps | DataScience | Machine Learning | ChatBots | Robotic Process Automation(RPA) | Coffee lover | Codes for a better world | Opinions = Mine