Skip to content

Ramblings on startups, NYC, advertising and hacking (mostly Python)

  • Home
  • Django
  • Hacking
  • Startups
  • Tech
  • Design
  • Madison Ave
  • All Posts

Author

Chris Kief is currently the Head of Technology at 360i and resides in New York City.

Top Posts

  • Django Generic DetailView without a PK or Slug
  • Checking if a GET Variable Exists in Django
  • How to Kill a Process by Port on OS X
  • Django Class-based Views with Multiple Forms
  • Combine 2 Django Querysets from Different Models
  • Django Form Wizard and Getting Data from Previous Steps
  • How to Remove the 2019 Fox Float X2 EVOL Air Sleeve
  • Django ModelForm and Conditionally Disabled (Readonly) Fields
  • Access Django Constants from settings.py in a Template
  • Django and MySQL + Emoticons

Tags

  • A16Z
  • AJAX
  • Amazon AWS
  • AWS
  • Basics
  • Celery
  • Chrome
  • Class-based Views
  • Collaboration Apps
  • Compressor
  • Design
  • Django
  • DNS
  • Facebook
  • Forms
  • Fred Wilson
  • Google
  • HipChat
  • IPO
  • MacPorts
  • Marc Andreessen
  • Mavericks
  • Mixins
  • ModelForms
  • Models
  • MySQL
  • Nginx
  • Node
  • NPM
  • NYC
  • Oauth
  • OS X
  • PHP
  • PIP
  • Pitching
  • PyCharm
  • Python
  • QA
  • RabbitMQ
  • RightScale
  • Settings
  • SSL
  • Startup School
  • Symfony2
  • Template Tag
  • Twitter
  • UX
  • VC
  • Views
  • Xcode

Follow me on Twitter

My Tweets

Tag: Metadata

Setting S3 Cache Metadata

By default Amazon’s S3 doesn’t set any Cache Control headers. Even worse, the only way to set them via their S3 management console is file-by-file.

Not exactly scalable.

Until they give us a quick and easy way to do this, here’s a simple Python script using Boto (thanks to Blackpawn).

Note that the script iterates over every object in your buckets, so if you have a ton of objects, it may not be the solution for you.


from boto.s3.connection import S3Connection
connection = S3Connection('aws access key', 'aws secret key')
buckets = connection.get_all_buckets()
for bucket in buckets:
for key in bucket.list():
print('%s' % key)
if key.name.endswith('.jpg'):
contentType = 'image/jpeg'
elif key.name.endswith('.png'):
contentType = 'image/png'
else:
continue
key.metadata.update({
'Content-Type': contentType,
'Cache-Control': 'max-age=864000'
})
key.copy(
key.bucket.name,
key.name,
key.metadata,
preserve_acl=True
)

view raw

s3.py

hosted with ❤ by GitHub

Share this:

  • Pocket
  • Twitter
  • LinkedIn
  • Facebook
  • More
  • Email
  • Reddit

Like this:

Like Loading...
Posted on July 13, 2014Categories HackingTags Amazon AWS, Caching, Metadata, S3Leave a comment on Setting S3 Cache Metadata
Blog at WordPress.com.
  • Follow Following
    • Ramblings on startups, NYC, advertising and hacking (mostly Python)
    • Join 475 other followers
    • Already have a WordPress.com account? Log in now.
    • Ramblings on startups, NYC, advertising and hacking (mostly Python)
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: