jmhobbs

Updating S3 CORS With Boto

Sometimes you don't have access to the S3 console, but you do have keys for a bucket. If you need to change CORS for that bucket, it turns out you can. Boto has API methods for this.

# -*- coding: utf-8 -*-

from boto.s3.connection import S3Connection
from boto.s3.bucket import Bucket

AWS_ACCESS_KEY = 'YOUR KEY HERE'
AWS_SECRET_KEY = 'YOUR KEY HERE'
S3_BUCKET = 'YOUR BUCKET HERE'

cors_xml = """

  
    *
    GET
    POST
    *
  

"""

connection = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
bucket = Bucket(connection, S3_BUCKET)

print "Current CORS:"
print bucket.get_cors_xml()

bucket.set_cors_xml(cors_xml)

print "New CORS:"
print bucket.get_cors_xml()