|
33 | 33 | # For more information about bucket name restrictions, see:
|
34 | 34 | # http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
|
35 | 35 | bucket_name = "python-sdk-sample-%s" % uuid.uuid4()
|
36 |
| -print "Creating new bucket with name: " + bucket_name |
| 36 | +print("Creating new bucket with name: " + bucket_name) |
37 | 37 | bucket = s3.create_bucket(bucket_name)
|
38 | 38 |
|
39 | 39 | # Files in Amazon S3 are called "objects" and are stored in buckets. A specific
|
|
46 | 46 | k = Key(bucket)
|
47 | 47 | k.key = 'python_sample_key.txt'
|
48 | 48 |
|
49 |
| -print "Uploading some data to " + bucket_name + " with key: " + k.key |
| 49 | +print ("Uploading some data to " + bucket_name + " with key: " + k.key) |
50 | 50 | k.set_contents_from_string('Hello World!')
|
51 | 51 |
|
52 | 52 | # Fetch the key to show that we stored something. Key.generate_url will
|
|
57 | 57 | # http://boto.readthedocs.org/en/latest/ref/s3.html#boto.s3.key.Key.generate_url
|
58 | 58 | expires_in_seconds = 1800
|
59 | 59 |
|
60 |
| -print "Generating a public URL for the object we just uploaded. This URL will be active for %d seconds" % expires_in_seconds |
61 |
| -print |
62 |
| -print k.generate_url(expires_in_seconds) |
63 |
| -print |
64 |
| -raw_input("Press enter to delete both the object and the bucket...") |
| 60 | +print("Generating a public URL for the object we just uploaded. This URL will be active for %d seconds" % expires_in_seconds) |
| 61 | +print('') |
| 62 | +print(k.generate_url(expires_in_seconds)) |
| 63 | +print('') |
| 64 | + |
| 65 | + |
| 66 | +try: input = raw_input |
| 67 | +except NameError: pass |
| 68 | +input("Press enter to delete both the object and the bucket...") |
65 | 69 |
|
66 | 70 | # Buckets cannot be deleted unless they're empty. Since we still have a
|
67 | 71 | # reference to the key (object), we can just delete it.
|
68 |
| -print "Deleting the object." |
| 72 | +print("Deleting the object.") |
69 | 73 | k.delete()
|
70 | 74 |
|
71 | 75 | # Now that the bucket is empty, we can delete it.
|
72 |
| -print "Deleting the bucket." |
| 76 | +print("Deleting the bucket.") |
73 | 77 | s3.delete_bucket(bucket_name)
|
0 commit comments