Skip to content

Commit 8ce0283

Browse files
authored
fix(stepfunctions-tasks): state machine role is missing sagemaker:AddTags permission for SageMakerCreateTransformJob task (#27264)
If we specified RUN_JOB as IntegrationPattern prop for SageMakerCreateTransformJob construct, StepFunctions executes SageMaker batch transform job [synchronously](https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-sync). In this case, StepFunctions add a tag (key: MANAGED_BY_AWS, value: STARTED_BY_STEP_FUNCTIONS) to the job, so state machine role needs the permission to do that. However, currently CDK does not add the permission automatically. This PR solves the issue by adding `sagemaker:AddTags` permission to state machine role when RUN_JOB is specified as IntegrationPattern prop. Closes #26012 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7ac237b commit 8ce0283

File tree

11 files changed

+1058
-0
lines changed

11 files changed

+1058
-0
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/sagemaker/integ.create-transform-job.js.snapshot/SqsTestDefaultTestDeployAssert659366A6.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/sagemaker/integ.create-transform-job.js.snapshot/SqsTestDefaultTestDeployAssert659366A6.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/sagemaker/integ.create-transform-job.js.snapshot/aws-cdk-step-functions-task-create-transform-job-integ.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"Resources": {
3+
"BatchInferenceTaskSagemakerTransformRoleEABCCE1A": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "sagemaker.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/AmazonSageMakerFullAccess"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"SimpleStateMachineRole0CBC135A": {
35+
"Type": "AWS::IAM::Role",
36+
"Properties": {
37+
"AssumeRolePolicyDocument": {
38+
"Statement": [
39+
{
40+
"Action": "sts:AssumeRole",
41+
"Effect": "Allow",
42+
"Principal": {
43+
"Service": "states.amazonaws.com"
44+
}
45+
}
46+
],
47+
"Version": "2012-10-17"
48+
}
49+
}
50+
},
51+
"SimpleStateMachineRoleDefaultPolicyF5E1CB8E": {
52+
"Type": "AWS::IAM::Policy",
53+
"Properties": {
54+
"PolicyDocument": {
55+
"Statement": [
56+
{
57+
"Action": [
58+
"sagemaker:AddTags",
59+
"sagemaker:CreateTransformJob",
60+
"sagemaker:DescribeTransformJob",
61+
"sagemaker:StopTransformJob"
62+
],
63+
"Effect": "Allow",
64+
"Resource": {
65+
"Fn::Join": [
66+
"",
67+
[
68+
"arn:",
69+
{
70+
"Ref": "AWS::Partition"
71+
},
72+
":sagemaker:",
73+
{
74+
"Ref": "AWS::Region"
75+
},
76+
":",
77+
{
78+
"Ref": "AWS::AccountId"
79+
},
80+
":transform-job/*"
81+
]
82+
]
83+
}
84+
},
85+
{
86+
"Action": "sagemaker:ListTags",
87+
"Effect": "Allow",
88+
"Resource": "*"
89+
},
90+
{
91+
"Action": "iam:PassRole",
92+
"Condition": {
93+
"StringEquals": {
94+
"iam:PassedToService": "sagemaker.amazonaws.com"
95+
}
96+
},
97+
"Effect": "Allow",
98+
"Resource": {
99+
"Fn::GetAtt": [
100+
"BatchInferenceTaskSagemakerTransformRoleEABCCE1A",
101+
"Arn"
102+
]
103+
}
104+
},
105+
{
106+
"Action": [
107+
"events:DescribeRule",
108+
"events:PutRule",
109+
"events:PutTargets"
110+
],
111+
"Effect": "Allow",
112+
"Resource": {
113+
"Fn::Join": [
114+
"",
115+
[
116+
"arn:",
117+
{
118+
"Ref": "AWS::Partition"
119+
},
120+
":events:",
121+
{
122+
"Ref": "AWS::Region"
123+
},
124+
":",
125+
{
126+
"Ref": "AWS::AccountId"
127+
},
128+
":rule/StepFunctionsGetEventsForSageMakerTransformJobsRule"
129+
]
130+
]
131+
}
132+
}
133+
],
134+
"Version": "2012-10-17"
135+
},
136+
"PolicyName": "SimpleStateMachineRoleDefaultPolicyF5E1CB8E",
137+
"Roles": [
138+
{
139+
"Ref": "SimpleStateMachineRole0CBC135A"
140+
}
141+
]
142+
}
143+
},
144+
"SimpleStateMachineE8E2CF40": {
145+
"Type": "AWS::StepFunctions::StateMachine",
146+
"Properties": {
147+
"DefinitionString": {
148+
"Fn::Join": [
149+
"",
150+
[
151+
"{\"StartAt\":\"BatchInferenceTask\",\"States\":{\"BatchInferenceTask\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:",
152+
{
153+
"Ref": "AWS::Partition"
154+
},
155+
":states:::sagemaker:createTransformJob.sync\",\"Parameters\":{\"ModelName\":\"MyModelName\",\"TransformInput\":{\"DataSource\":{\"S3DataSource\":{\"S3Uri\":\"s3://inputbucket/prefix\",\"S3DataType\":\"S3Prefix\"}}},\"TransformJobName\":\"MyTransformJob\",\"TransformOutput\":{\"S3OutputPath\":\"s3://outputbucket/result\"},\"TransformResources\":{\"InstanceCount\":1,\"InstanceType\":\"ml.m4.xlarge\"}}}}}"
156+
]
157+
]
158+
},
159+
"RoleArn": {
160+
"Fn::GetAtt": [
161+
"SimpleStateMachineRole0CBC135A",
162+
"Arn"
163+
]
164+
}
165+
},
166+
"DependsOn": [
167+
"SimpleStateMachineRoleDefaultPolicyF5E1CB8E",
168+
"SimpleStateMachineRole0CBC135A"
169+
],
170+
"UpdateReplacePolicy": "Delete",
171+
"DeletionPolicy": "Delete"
172+
}
173+
},
174+
"Parameters": {
175+
"BootstrapVersion": {
176+
"Type": "AWS::SSM::Parameter::Value<String>",
177+
"Default": "/cdk-bootstrap/hnb659fds/version",
178+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
179+
}
180+
},
181+
"Rules": {
182+
"CheckBootstrapVersion": {
183+
"Assertions": [
184+
{
185+
"Assert": {
186+
"Fn::Not": [
187+
{
188+
"Fn::Contains": [
189+
[
190+
"1",
191+
"2",
192+
"3",
193+
"4",
194+
"5"
195+
],
196+
{
197+
"Ref": "BootstrapVersion"
198+
}
199+
]
200+
}
201+
]
202+
},
203+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
204+
}
205+
]
206+
}
207+
}
208+
}

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/sagemaker/integ.create-transform-job.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/sagemaker/integ.create-transform-job.js.snapshot/integ.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)