@@ -61,34 +61,12 @@ def __init__(
6161 name = f"{ dep_mod } -EMRCluster" ,
6262 )
6363
64- # policy to let Lambda invoke the api
65- custom_policy_document = iam .PolicyDocument (
66- statements = [
67- iam .PolicyStatement (
68- effect = iam .Effect .ALLOW ,
69- actions = [
70- "ec2:CreateSecurityGroup" ,
71- "ec2:RevokeSecurityGroupEgress" ,
72- "ec2:CreateSecurityGroup" ,
73- "ec2:DeleteSecurityGroup" ,
74- "ec2:AuthorizeSecurityGroupEgress" ,
75- "ec2:AuthorizeSecurityGroupIngress" ,
76- "ec2:RevokeSecurityGroupIngress" ,
77- "ec2:DeleteSecurityGroup" ,
78- ],
79- resources = ["*" ],
80- )
81- ]
82- )
83- managed_policy = iam .ManagedPolicy (self , f"{ id } -ManagedPolicy" , document = custom_policy_document )
84-
8564 self .role = iam .Role (
8665 scope = self ,
8766 id = f"{ id } -LambdaRole" ,
8867 assumed_by = iam .ServicePrincipal ("lambda.amazonaws.com" ),
8968 managed_policies = [
9069 iam .ManagedPolicy .from_aws_managed_policy_name ("service-role/AWSLambdaBasicExecutionRole" ),
91- managed_policy ,
9270 ],
9371 )
9472
@@ -176,12 +154,32 @@ def __init__(
176154 self ,
177155 "StudioServiceRole" ,
178156 assumed_by = iam .ServicePrincipal ("elasticmapreduce.amazonaws.com" ),
179- managed_policies = [iam .ManagedPolicy .from_aws_managed_policy_name ("AmazonS3FullAccess" )],
180157 )
181158 Tags .of (role ).add ("for-use-with-amazon-emr-managed-policies" , "true" )
182159 role .add_to_policy (
183160 iam .PolicyStatement (
184- resources = ["*" ],
161+ resources = [
162+ f"arn:aws:s3:::{ artifact_bucket_name } " ,
163+ f"arn:aws:s3:::{ artifact_bucket_name } /*" ,
164+ ],
165+ actions = [
166+ "s3:GetObject" ,
167+ "s3:PutObject" ,
168+ "s3:DeleteObject" ,
169+ "s3:ListBucket" ,
170+ "s3:GetBucketLocation" ,
171+ ],
172+ effect = iam .Effect .ALLOW ,
173+ )
174+ )
175+ role .add_to_policy (
176+ iam .PolicyStatement (
177+ resources = [
178+ f"arn:aws:ec2:{ self .region } :{ self .account } :vpc/{ vpc_id } " ,
179+ f"arn:aws:ec2:{ self .region } :{ self .account } :subnet/*" ,
180+ f"arn:aws:ec2:{ self .region } :{ self .account } :security-group/*" ,
181+ f"arn:aws:ec2:{ self .region } :{ self .account } :network-interface/*" ,
182+ ],
185183 actions = [
186184 "ec2:AuthorizeSecurityGroupEgress" ,
187185 "ec2:AuthorizeSecurityGroupIngress" ,
@@ -200,6 +198,17 @@ def __init__(
200198 "ec2:DescribeInstances" ,
201199 "ec2:DescribeSubnets" ,
202200 "ec2:DescribeVpcs" ,
201+ ],
202+ effect = iam .Effect .ALLOW ,
203+ )
204+ )
205+ role .add_to_policy (
206+ iam .PolicyStatement (
207+ resources = [
208+ f"arn:aws:elasticmapreduce:{ self .region } :{ self .account } :cluster/*" ,
209+ f"arn:aws:emr-containers:{ self .region } :{ self .account } :/virtualclusters/*" ,
210+ ],
211+ actions = [
203212 "elasticmapreduce:ListInstances" ,
204213 "elasticmapreduce:DescribeCluster" ,
205214 "elasticmapreduce:ListSteps" ,
0 commit comments