-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure-aws-cli.template.py
39 lines (29 loc) · 1.17 KB
/
configure-aws-cli.template.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
import os
from glob import glob
from subprocess import check_output, CalledProcessError
import yaml
ACCOUNT_ID = os.environ['ACCOUNT_ID']
def run(command):
print('Running', command)
try:
output = check_output(command.split(' ')).decode('utf-8')
return output
except CalledProcessError as exc:
print("Status : FAIL", exc.returncode, exc.output.decode('utf-8'))
def _configure_profile(profile_name, profile_role):
print('Got', profile_role, 'for', profile_name)
if profile_name != 'default':
profile_name = f'profile.{profile_name}'
run(f'aws configure set {profile_name}.region us-east-1')
run(f'aws configure set {profile_name}.credential_source EcsContainer')
if profile_role:
run(f'aws configure set {profile_name}.role_arn {profile_role}')
def go():
for path in glob('config/app/*/config.yaml'):
parsed = yaml.load(open(path))
profile_name = parsed['profile']
account_id = parsed.get('account_id', ACCOUNT_ID)
_configure_profile(profile_name, f'arn:aws:iam::{account_id}:role/${PROJECT_NAME}-target')
_configure_profile('default', None)
if __name__ == '__main__':
go()