-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupdate_credentials.py
More file actions
42 lines (31 loc) · 1.36 KB
/
update_credentials.py
File metadata and controls
42 lines (31 loc) · 1.36 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
import os
import boto3
def get_account_id():
client = boto3.client("sts")
return client.get_caller_identity()["Account"]
def get_default_region():
my_session = boto3.session.Session()
return my_session.region_name
# Replace the following
account_id = get_account_id()
region_id = get_default_region()
def replace_string(action, original_str, replaced_str, directory):
for dname, dirs, files in os.walk(directory):
for fname in files:
folder_name = dname.split('/')[-1]
if ('.py' in fname or '.json' in fname) and folder_name != 'utils' and folder_name != '__pycache__' and fname != '__init__.py':
print(action, 'id in', dname, fname)
fpath = os.path.join(dname, fname)
with open(fpath) as f:
s = f.read()
s = s.replace(original_str, replaced_str)
with open(fpath, "w") as f:
f.write(s)
replace_string('Updated account', '<AWS-ACCOUNT-ID>',
str(account_id), '../orchestration_demos/')
replace_string('Updated region', '<AWS-REGION-ID>',
str(region_id), '../orchestration_demos/')
replace_string('Updated account', '<AWS-ACCOUNT-ID>',
str(account_id), '../../tests/')
replace_string('Updated region', '<AWS-REGION-ID>',
str(region_id), '../../tests/')