Uh oh!
There was an error while loading. Please reload this page.
forked from SumoLogic/sumologic-aws-lambda
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_function.py
More file actions
Latest commit
112 lines (90 loc) · 3.41 KB
/
Copy pathdeploy_function.py
File metadata and controls
112 lines (90 loc) · 3.41 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
importboto3
importos
fromargparseimportArgumentParser
regions= [
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"ap-south-1",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
# "cn-north-1",
# "ap-northeast-3", #giving errror
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"eu-north-1",
"sa-east-1",
"ap-east-1",
"me-south-1",
"eu-south-1",
"af-south-1"
]
defget_bucket_name(bucket_prefix, region):
ifregionin ("eu-north-1", "me-south-1", "ap-east-1", "af-south-1"):
return'%s-%ss'% (bucket_prefix, region)
return'%s-%s'% (bucket_prefix, region)
defupload_code_in_multiple_regions(filepath, bucket_prefix):
forregioninregions:
upload_code_in_S3(filepath, get_bucket_name(bucket_prefix, region), region)
defcreate_buckets(bucket_prefix):
forregioninregions:
s3=boto3.client('s3', region)
bucket_name=get_bucket_name(bucket_prefix, region)
try:
ifregion=="us-east-1":
response=s3.create_bucket(Bucket=bucket_name) # the operation is idempotent
else:
response=s3.create_bucket(Bucket=bucket_name,
CreateBucketConfiguration={
'LocationConstraint': region
})
print("Creating bucket", region, response)
exceptExceptionase:
print(bucket_name, region)
print(e)
defupload_code_in_S3(filepath, bucket_name, region):
print("Uploading zip file in S3", region)
s3=boto3.client('s3', region)
filename=os.path.basename(filepath)
s3.upload_file(filepath, bucket_name, filename,
ExtraArgs={'ACL': 'public-read'})
defupload_cftemplate(templatepath, bucket_name, region='us-east-1'):
print("Uploading template file in S3")
s3=boto3.client('s3', region)
filename=os.path.basename(templatepath)
s3.upload_file(templatepath, bucket_name, filename,
ExtraArgs={'ACL': 'public-read'})
if__name__=='__main__':
parser=ArgumentParser()
parser.add_argument("-t", "--templatefile", dest="templatefile",
help="CF template")
parser.add_argument("-z", "--zipfile", dest="zipfile",
help="deployment package")
parser.add_argument("-d", "--deployment", dest="deployment", default="dev",
help="aws account type")
args=parser.parse_args()
ifargs.deployment=="prod":
zip_bucket_prefix="appdevzipfiles"
template_bucket="appdev-cloudformation-templates"
else:
zip_bucket_prefix="appdevstore"
template_bucket="cf-templates-5d0x5unchag-us-east-1"
# create_buckets(zip_bucket_prefix)
print(args)
ifargs.templatefile:
ifnotos.path.isfile(args.templatefile):
raiseException("templatefile does not exists")
else:
upload_cftemplate(args.templatefile, template_bucket)
ifargs.zipfile:
ifnotos.path.isfile(args.zipfile):
raiseException("zipfile does not exists")
else:
upload_code_in_multiple_regions(args.zipfile, zip_bucket_prefix)
print("Deployment Successfull: ALL files copied to %s"%args.deployment)