-
Notifications
You must be signed in to change notification settings - Fork 16
/
run_create_lambda_iam.py
executable file
·35 lines (27 loc) · 1.22 KB
/
run_create_lambda_iam.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
#!/usr/bin/env python3
from run_common import AWSCli
from run_common import print_message
aws_cli = AWSCli()
def create_iam_for_lambda(git_folder_name, folder_name, function_name):
sleep_required = False
replaced_function_name = function_name.replace('_', '-')
role_name = f'lambda-{replaced_function_name}-role'
if not aws_cli.get_iam_role(role_name):
print_message('create iam role')
role_file_path = f'file://template/{git_folder_name}/lambda/{folder_name}/iam/role.json'
cmd = ['iam', 'create-role']
cmd += ['--role-name', role_name]
cmd += ['--assume-role-policy-document', role_file_path]
aws_cli.run(cmd)
sleep_required = True
policy_name = f'lambda-{replaced_function_name}-policy'
if not aws_cli.get_iam_role_policy(role_name, policy_name):
print_message('put iam role policy')
policy_file_path = f'file://template/{git_folder_name}/lambda/{folder_name}/iam/policy.json'
cmd = ['iam', 'put-role-policy']
cmd += ['--role-name', role_name]
cmd += ['--policy-name', policy_name]
cmd += ['--policy-document', policy_file_path]
aws_cli.run(cmd)
sleep_required = True
return sleep_required