-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-certbot-to-acm.py
executable file
·51 lines (37 loc) · 1.41 KB
/
deploy-certbot-to-acm.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""\
Usage: deploy-certbot-to-acm.py [--region <region>]
Deploy certbot-to-acm Lambda function ZIP file.
Options:
-h | --help
Show this usage information.
-r <region> | --region <region>
Use the specified AWS region. This must be specified.
"""
from concurrent.futures import ThreadPoolExecutor
from sys import argv, exit as sys_exit
from boto3.session import Session
def deploy(region, profile):
b3 = Session(region_name=region, profile_name=profile)
s3 = b3.client("s3")
s3_bucket = f"ionosphere-public-{region}"
filename = "certbot-to-acm.zip"
with open(filename, "rb") as fd:
s3.put_object(ACL="public-read", Body=fd, Bucket=s3_bucket, Key=filename)
def main(args):
with open(".profiles.txt", "r") as fd:
profiles = fd.read().strip().split("\n")
region_profiles = []
for profile in profiles:
ec2 = Session(profile_name=profile).client("ec2")
regions = [r["RegionName"] for r in ec2.describe_regions()["Regions"]]
for region in regions:
region_profiles.append((region, profile))
region_profiles.sort()
with ThreadPoolExecutor(max_workers=2 * len(region_profiles)) as tpe:
futures = [tpe.submit(deploy, region, profile) for region, profile in region_profiles]
for future in futures:
future.result()
return 0
if __name__ == "__main__":
sys_exit(main(argv[1:]))