forked from awslabs/lambda-refarch-mapreduce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-biglambda-role.py
37 lines (31 loc) · 904 Bytes
/
create-biglambda-role.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
import boto3,json,botocore
client = boto3.client('iam')
trust_role = {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
rn='biglambda_role'
rp='biglambda_policy'
try:
response = client.create_role(RoleName=rn,AssumeRolePolicyDocument=json.dumps(trust_role))
print response['Role']['Arn']
print "Success: done creating role"
except botocore.exceptions.ClientError as e:
print "Error: {0}".format(e)
try:
with open('policy.json') as json_data:
response = client.put_role_policy(RoleName=rn,PolicyName=rp,
PolicyDocument=json.dumps(json.load(json_data))
)
print "Success: done adding inline policy to role"
except botocore.exceptions.ClientError as e:
print "Error: {0}".format(e)