Skip to content

Commit f4d5b4c

Browse files
authored
[policies] Return the Arn of ParallelClusterLambdaRole in output of policies substack (aws#4847)
* `[policies]` Return the Arn of the UserRole in the output of the policies substack. * `[policies]` Return a Lambda role to be specific on its use case.
1 parent bfedbc0 commit f4d5b4c

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

cloudformation/policies/parallelcluster-policies.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ Outputs:
7878
Condition: EnableFSxS3AccessCondition
7979
Value: !Ref ParallelClusterFSxS3AccessPolicy
8080

81-
ParallelClusterUserRole:
82-
Value: !Ref ParallelClusterUserRole
81+
ParallelClusterLambdaRoleArn:
82+
Value: !GetAtt ParallelClusterLambdaRole.Arn
8383

8484
DefaultParallelClusterIamAdminPolicy:
8585
Condition: EnableIamPolicy
@@ -111,7 +111,7 @@ Resources:
111111
Condition: EnableIamPolicy
112112
Properties:
113113
Roles:
114-
- !Ref ParallelClusterUserRole
114+
- !Ref ParallelClusterLambdaRole
115115
PolicyDocument:
116116
Version: '2012-10-17'
117117
Statement:
@@ -175,7 +175,7 @@ Resources:
175175
Sid: IamPolicy
176176

177177

178-
ParallelClusterUserRole:
178+
ParallelClusterLambdaRole:
179179
Type: AWS::IAM::Role
180180
Properties:
181181
AssumeRolePolicyDocument:
@@ -185,6 +185,9 @@ Resources:
185185
Principal:
186186
Service: lambda.amazonaws.com
187187
ManagedPolicyArns:
188+
# Required for Lambda logging and XRay
189+
- !Sub arn:${AWS::Partition}:iam::aws:policy/AWSXRayDaemonWriteAccess
190+
- !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
188191
# Required to run ParallelCluster functionalities
189192
- !Ref ParallelClusterClusterPolicy
190193
- !If
@@ -307,7 +310,7 @@ Resources:
307310
Effect: Allow
308311
Sid: EnableFSxS3Access
309312
Roles:
310-
- !Ref ParallelClusterUserRole
313+
- !Ref ParallelClusterLambdaRole
311314

312315
ParallelClusterClusterPolicy:
313316
Type: AWS::IAM::ManagedPolicy

cloudformation/tests/test_policies.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,31 @@ def test_match_api():
8989
for key in policies["Resources"].keys():
9090
drop_keys = {"Condition"}
9191

92-
source_key = {"ParallelClusterFSxS3AccessPolicy": "FSxS3AccessPolicy"}.get(key, key)
92+
source_key = {
93+
"ParallelClusterFSxS3AccessPolicy": "FSxS3AccessPolicy",
94+
"ParallelClusterLambdaRole": "ParallelClusterUserRole",
95+
}.get(key, key)
96+
9397
source_dict = {k: v for k, v in source["Resources"][source_key].items() if k not in drop_keys}
9498
dest_dict = {k: v for k, v in policies["Resources"][key].items() if k not in drop_keys}
9599

96-
if key == "ParallelClusterUserRole":
97-
source_dict["Properties"]["ManagedPolicyArns"] = source_dict["Properties"]["ManagedPolicyArns"][2:]
100+
if key == "ParallelClusterLambdaRole":
98101

99102
def remove_batch_if(arn):
100-
return arn if "Ref" in arn else arn["Fn::If"][1]
103+
return arn if ("Ref" in arn or "Fn::Sub" in arn) else arn["Fn::If"][1]
101104

102105
dest_dict["Properties"]["ManagedPolicyArns"] = list(
103106
map(remove_batch_if, dest_dict["Properties"]["ManagedPolicyArns"])
104107
)
105108

109+
# Rename UserRole to LambdaRole, ignore policy name mismatch
106110
if key == "ParallelClusterFSxS3AccessPolicy":
111+
source_dict["Properties"]["Roles"][0]["Ref"] = "ParallelClusterLambdaRole"
107112
del source_dict["Properties"]["PolicyName"]
108113
del dest_dict["Properties"]["PolicyName"]
109114

115+
# Rename UserRole to LambdaRole
116+
if key == "DefaultParallelClusterIamAdminPolicy":
117+
source_dict["Properties"]["Roles"][0]["Ref"] = "ParallelClusterLambdaRole"
118+
110119
assert_that(dest_dict).is_equal_to(source_dict)

0 commit comments

Comments
 (0)