title: Why are my Amazon S3 key permissions not sticking?
body: <p>I'm using the Python library <code>boto</code> to connect to Amazon S3 and create buckets and keys for a static website.  My keys and values are dynamically generated, hence why I am doing this programmatically and not through the web interface (it works using the web interface).  My code currently looks like this:</p>
  
  <pre><code>import boto
  from boto.s3.connection import S3Connection
  from boto.s3.key import Key
  
  conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  bucket = conn.create_bucket(BUCKET_NAME)
  bucket.configure_website('index.html', 'error.html')
  bucket.set_acl('public-read')
  
  for template in ['index.html', 'contact-us.html', 'cart.html', 'checkout.html']:
      k = Key(bucket)
      k.key = key
      k.set_acl('public-read')
      k.set_metadata('Content-Type', 'text/html')
      k.set_contents_from_string(get_page_contents(template))
  </code></pre>
  
  <p>I'm getting various errors and problems with this code.  When the keys already existed and I used this code to update them, I would set the ACL of each key to <code>public-read</code>, but I'd still get 403 forbidden errors when viewing the file in a browser.</p>
  
  <p>I tried removing all the keys to recreate them from scratch, and now I get a <code>NoSuchKey</code> exception.  Obviously the key isn't there because I'm trying to create it.</p>
  
  <p>Am I going about this the wrong way?  Is there a different way of doing this to create the keys as opposed to updating them?  And am I experiencing some kind of race condition when the permissions don't stick?</p>