-
Notifications
You must be signed in to change notification settings - Fork 34
/
set_ampcamp_ami.py
37 lines (32 loc) · 1.03 KB
/
set_ampcamp_ami.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto
from optparse import OptionParser
from boto import *
def main():
parser = OptionParser(usage="set_ampcamp_ami.py <ami-id>",
add_help_option=True)
(opts, args) = parser.parse_args()
if len(args) != 1:
print "Current AMI ID is " + get_s3_kv("ampcamp-amis", "latest-ampcamp3")
parser.print_help()
sys.exit(1)
else:
set_s3_kv("ampcamp-amis", "latest-ampcamp3", args[0])
def set_s3_kv(bucket, key, value):
conn = connect_s3()
s3_bucket = conn.get_bucket(bucket)
s3_key = s3_bucket.get_key(key)
old_value = s3_key.get_contents_as_string()
s3_key.set_contents_from_string(value)
s3_key.set_acl('public-read')
new_value = s3_key.get_contents_as_string()
print "Changed value of " + key + " from " + old_value + " to " + new_value
def get_s3_kv(bucket, key):
conn = connect_s3()
s3_bucket = conn.get_bucket(bucket)
s3_key = s3_bucket.get_key(key)
old_value = s3_key.get_contents_as_string()
return old_value
if __name__ == "__main__":
main()