Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fda4546

Browse files
PavanRanguduDahlberg Victor
authored and
Dahlberg Victor
committedJun 10, 2024
feat(stepfunctions-tasks): support for the step functions mediaconvert optimized integration for createJob api (aws#30300)
Step Functions recently released an [Optimized Integration for MediaConvert CreateJob API](https://docs.aws.amazon.com/step-functions/latest/dg/connect-mediaconvert.html) and these changes add support for the MediaConvert CreateJob task to Step Functions state machines. ### Issue # (if applicable) Closes [aws#30299](aws#30299) ### Reason for this change The aws-stepfunctions-tasks now needs to support creating MediaConvert CreateJob tasks ### Description of changes Added a new L2 construct for MediaConvert Create-Job Task: ``packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/mediaconvert/create-job.ts`` ### Description of how you validated changes Unit test - ``packages/aws-cdk-lib/aws-stepfunctions-tasks/test/mediaconvert/create-job.test.ts`` Integration test - ``packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/mediaconvert/test/integ.create-job.ts`` Verified the State Machine with MediaConvert CreateJob Task with all the necessary permissions ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c00ace0 commit fda4546

13 files changed

+1105
-0
lines changed
 

‎packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/mediaconvert/test/integ.create-job.js.snapshot/MediaConvertCreateJobTestDefaultTestDeployAssertA293ABFD.assets.json

+19
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/mediaconvert/test/integ.create-job.js.snapshot/MediaConvertCreateJobTestDefaultTestDeployAssertA293ABFD.template.json

+36
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/mediaconvert/test/integ.create-job.js.snapshot/aws-cdk-mediaconvert-create-job-test-stack.assets.json

+19
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,115 @@
1+
{
2+
"Resources": {
3+
"StateMachineRoleB840431D": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "states.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
}
18+
}
19+
},
20+
"StateMachineRoleDefaultPolicyDF1E6607": {
21+
"Type": "AWS::IAM::Policy",
22+
"Properties": {
23+
"PolicyDocument": {
24+
"Statement": [
25+
{
26+
"Action": "iam:PassRole",
27+
"Condition": {
28+
"StringLike": {
29+
"iam:PassedToService": "mediaconvert.amazonaws.com"
30+
}
31+
},
32+
"Effect": "Allow",
33+
"Resource": "arn:aws:iam::123456789012:role/MediaConvertRole"
34+
},
35+
{
36+
"Action": "mediaconvert:CreateJob",
37+
"Effect": "Allow",
38+
"Resource": "*"
39+
}
40+
],
41+
"Version": "2012-10-17"
42+
},
43+
"PolicyName": "StateMachineRoleDefaultPolicyDF1E6607",
44+
"Roles": [
45+
{
46+
"Ref": "StateMachineRoleB840431D"
47+
}
48+
]
49+
}
50+
},
51+
"StateMachine2E01A3A5": {
52+
"Type": "AWS::StepFunctions::StateMachine",
53+
"Properties": {
54+
"DefinitionString": {
55+
"Fn::Join": [
56+
"",
57+
[
58+
"{\"StartAt\":\"MediaConvertCreateJob\",\"States\":{\"MediaConvertCreateJob\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:",
59+
{
60+
"Ref": "AWS::Partition"
61+
},
62+
":states:::mediaconvert:createJob\",\"Parameters\":{\"Role\":\"arn:aws:iam::123456789012:role/MediaConvertRole\",\"Settings\":{\"OutputGroups\":[{\"Outputs\":[{\"ContainerSettings\":{\"Container\":\"MP4\"},\"VideoDescription\":{\"CodecSettings\":{\"Codec\":\"H_264\",\"H264Settings\":{\"MaxBitrate\":1000,\"RateControlMode\":\"QVBR\",\"SceneChangeDetect\":\"TRANSITION_DETECTION\"}}},\"AudioDescriptions\":[{\"CodecSettings\":{\"Codec\":\"AAC\",\"AacSettings\":{\"Bitrate\":96000,\"CodingMode\":\"CODING_MODE_2_0\",\"SampleRate\":48000}}}]}],\"OutputGroupSettings\":{\"Type\":\"FILE_GROUP_SETTINGS\",\"FileGroupSettings\":{\"Destination\":\"s3://EXAMPLE-DESTINATION-BUCKET/\"}}}],\"Inputs\":[{\"AudioSelectors\":{\"Audio Selector 1\":{\"DefaultSelection\":\"DEFAULT\"}},\"FileInput\":\"s3://EXAMPLE-SOURCE-BUCKET/EXAMPLE-SOURCE_FILE\"}]}}}}}"
63+
]
64+
]
65+
},
66+
"RoleArn": {
67+
"Fn::GetAtt": [
68+
"StateMachineRoleB840431D",
69+
"Arn"
70+
]
71+
}
72+
},
73+
"DependsOn": [
74+
"StateMachineRoleDefaultPolicyDF1E6607",
75+
"StateMachineRoleB840431D"
76+
],
77+
"UpdateReplacePolicy": "Delete",
78+
"DeletionPolicy": "Delete"
79+
}
80+
},
81+
"Parameters": {
82+
"BootstrapVersion": {
83+
"Type": "AWS::SSM::Parameter::Value<String>",
84+
"Default": "/cdk-bootstrap/hnb659fds/version",
85+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
86+
}
87+
},
88+
"Rules": {
89+
"CheckBootstrapVersion": {
90+
"Assertions": [
91+
{
92+
"Assert": {
93+
"Fn::Not": [
94+
{
95+
"Fn::Contains": [
96+
[
97+
"1",
98+
"2",
99+
"3",
100+
"4",
101+
"5"
102+
],
103+
{
104+
"Ref": "BootstrapVersion"
105+
}
106+
]
107+
}
108+
]
109+
},
110+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
111+
}
112+
]
113+
}
114+
}
115+
}

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

+1
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/mediaconvert/test/integ.create-job.js.snapshot/integ.json

+12
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/mediaconvert/test/integ.create-job.js.snapshot/manifest.json

+125
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,99 @@
1+
import * as iam from 'aws-cdk-lib/aws-iam';
2+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
3+
import { App, Stack } from 'aws-cdk-lib';
4+
import { MediaConvertCreateJob } from 'aws-cdk-lib/aws-stepfunctions-tasks';
5+
import { IntegTest } from '@aws-cdk/integ-tests-alpha/lib';
6+
7+
/*
8+
* Creates a state machine that creates a MediaConvert Job.
9+
* https://docs.aws.amazon.com/step-functions/latest/dg/connect-mediaconvert.html
10+
*
11+
* Stack verification steps:
12+
*
13+
* Before we execute the state machine, we need to update the following fields in the state machine definition
14+
* Role: https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-role
15+
* Settings: https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-settings
16+
*
17+
* Once updated, the generated state machine can be executed from the CLI (or Step Functions console)
18+
* and runs with an execution status of `Succeeded` & output contains the MediaConvert Job ARN
19+
*
20+
* -- aws stepfunctions start-execution --state-machine-arn <state-machine-arn> provides execution arn
21+
* -- aws stepfunctions describe-execution --execution-arn <execution-arn> returns a status of `Succeeded`
22+
*
23+
* We can also check for the MediaConvert Job status from the CLI (or Media Convert console)
24+
*
25+
* -- aws mediaconvert get-job --id <job-id>
26+
*
27+
*/
28+
const app = new App();
29+
30+
const stack = new Stack(app, 'aws-cdk-mediaconvert-create-job-test-stack');
31+
32+
const mediaConvertRole = iam.Role.fromRoleArn(stack, 'MediaConvertRole', 'arn:aws:iam::123456789012:role/MediaConvertRole');
33+
34+
const step = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
35+
createJobRequest: {
36+
Role: mediaConvertRole.roleArn,
37+
Settings: {
38+
OutputGroups: [
39+
{
40+
Outputs: [
41+
{
42+
ContainerSettings: {
43+
Container: 'MP4',
44+
},
45+
VideoDescription: {
46+
CodecSettings: {
47+
Codec: 'H_264',
48+
H264Settings: {
49+
MaxBitrate: 1000,
50+
RateControlMode: 'QVBR',
51+
SceneChangeDetect: 'TRANSITION_DETECTION',
52+
},
53+
},
54+
},
55+
AudioDescriptions: [
56+
{
57+
CodecSettings: {
58+
Codec: 'AAC',
59+
AacSettings: {
60+
Bitrate: 96000,
61+
CodingMode: 'CODING_MODE_2_0',
62+
SampleRate: 48000,
63+
},
64+
},
65+
},
66+
],
67+
},
68+
],
69+
OutputGroupSettings: {
70+
Type: 'FILE_GROUP_SETTINGS',
71+
FileGroupSettings: {
72+
Destination: 's3://EXAMPLE-DESTINATION-BUCKET/',
73+
},
74+
},
75+
},
76+
],
77+
Inputs: [
78+
{
79+
AudioSelectors: {
80+
'Audio Selector 1': {
81+
DefaultSelection: 'DEFAULT',
82+
},
83+
},
84+
FileInput: 's3://EXAMPLE-SOURCE-BUCKET/EXAMPLE-SOURCE_FILE',
85+
},
86+
],
87+
},
88+
},
89+
});
90+
91+
new sfn.StateMachine(stack, 'StateMachine', {
92+
definition: step,
93+
});
94+
95+
new IntegTest(app, 'MediaConvertCreateJobTest', {
96+
testCases: [stack],
97+
});
98+
99+
app.synth();

‎packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md

+77
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aw
6767
- [Start Job Run](#start-job-run-1)
6868
- [Lambda](#lambda)
6969
- [Invoke](#invoke)
70+
- [MediaConvert](#mediaconvert)
71+
- [Create Job](#create-job)
7072
- [SageMaker](#sagemaker)
7173
- [Create Training Job](#create-training-job)
7274
- [Create Transform Job](#create-transform-job)
@@ -1290,6 +1292,81 @@ As a best practice, the `LambdaInvoke` task will retry on those errors with an i
12901292
a back-off rate of 2 and 6 maximum attempts. Set the `retryOnServiceExceptions` prop to `false` to
12911293
disable this behavior.
12921294

1295+
## MediaConvert
1296+
1297+
Step Functions supports [AWS MediaConvert](https://docs.aws.amazon.com/step-functions/latest/dg/connect-mediaconvert.html) through the Optimized integration pattern.
1298+
1299+
### CreateJob
1300+
1301+
The [CreateJob](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost) API creates a new transcoding job.
1302+
For information about jobs and job settings, see the User Guide at http://docs.aws.amazon.com/mediaconvert/latest/ug/what-is.html
1303+
1304+
You can call the `CreateJob` API from a `Task` state. Optionally you can specify the `integrationPattern`.
1305+
1306+
Make sure you update the required fields - [Role](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-role) &
1307+
[Settings](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-settings) and refer
1308+
[CreateJobRequest](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-model-createjobrequest) for all other optional parameters.
1309+
1310+
```ts
1311+
new tasks.MediaConvertCreateJob(this, 'CreateJob', {
1312+
createJobRequest: {
1313+
"Role": "arn:aws:iam::123456789012:role/MediaConvertRole",
1314+
"Settings": {
1315+
"OutputGroups": [
1316+
{
1317+
"Outputs": [
1318+
{
1319+
"ContainerSettings": {
1320+
"Container": "MP4"
1321+
},
1322+
"VideoDescription": {
1323+
"CodecSettings": {
1324+
"Codec": "H_264",
1325+
"H264Settings": {
1326+
"MaxBitrate": 1000,
1327+
"RateControlMode": "QVBR",
1328+
"SceneChangeDetect": "TRANSITION_DETECTION"
1329+
}
1330+
}
1331+
},
1332+
"AudioDescriptions": [
1333+
{
1334+
"CodecSettings": {
1335+
"Codec": "AAC",
1336+
"AacSettings": {
1337+
"Bitrate": 96000,
1338+
"CodingMode": "CODING_MODE_2_0",
1339+
"SampleRate": 48000
1340+
}
1341+
}
1342+
}
1343+
]
1344+
}
1345+
],
1346+
"OutputGroupSettings": {
1347+
"Type": "FILE_GROUP_SETTINGS",
1348+
"FileGroupSettings": {
1349+
"Destination": "s3://EXAMPLE-DESTINATION-BUCKET/"
1350+
}
1351+
}
1352+
}
1353+
],
1354+
"Inputs": [
1355+
{
1356+
"AudioSelectors": {
1357+
"Audio Selector 1": {
1358+
"DefaultSelection": "DEFAULT"
1359+
}
1360+
},
1361+
"FileInput": "s3://EXAMPLE-SOURCE-BUCKET/EXAMPLE-SOURCE_FILE"
1362+
}
1363+
]
1364+
}
1365+
},
1366+
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
1367+
});
1368+
```
1369+
12931370
## SageMaker
12941371

12951372
Step Functions supports [AWS SageMaker](https://docs.aws.amazon.com/step-functions/latest/dg/connect-sagemaker.html) through the service integration pattern.

‎packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ export * from './eventbridge/put-events';
5555
export * from './aws-sdk/call-aws-service';
5656
export * from './bedrock/invoke-model';
5757
export * from './http/invoke';
58+
export * from './mediaconvert/create-job';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { Construct } from 'constructs';
2+
import * as iam from '../../../aws-iam';
3+
import * as sfn from '../../../aws-stepfunctions';
4+
import { Stack } from '../../../core';
5+
import * as cdk from '../../../core';
6+
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
7+
8+
/**
9+
* Properties for creating a MediaConvert Job
10+
*
11+
* See the CreateJob API for complete documentation
12+
* @see https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost
13+
*
14+
*/
15+
export interface MediaConvertCreateJobProps extends sfn.TaskStateBaseProps {
16+
17+
/**
18+
* The input data for the MediaConvert Create Job invocation
19+
*/
20+
readonly createJobRequest: { [key: string]: any };
21+
22+
}
23+
24+
/**
25+
* A Step Functions Task to create a job in MediaConvert.
26+
*
27+
* The JobConfiguration/Request Syntax is defined in the Parameters in the Task State
28+
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-mediaconvert.html
29+
*
30+
* Response syntax: see CreateJobResponse schema
31+
* https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-response-examples
32+
*
33+
*/
34+
export class MediaConvertCreateJob extends sfn.TaskStateBase {
35+
36+
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [
37+
sfn.IntegrationPattern.REQUEST_RESPONSE,
38+
sfn.IntegrationPattern.RUN_JOB,
39+
];
40+
41+
protected readonly taskMetrics: sfn.TaskMetricsConfig | undefined;
42+
protected readonly taskPolicies: iam.PolicyStatement[] | undefined;
43+
44+
private readonly integrationPattern: sfn.IntegrationPattern;
45+
46+
constructor(scope: Construct, id: string, private readonly props: MediaConvertCreateJobProps) {
47+
super(scope, id, props);
48+
49+
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE;
50+
validatePatternSupported(this.integrationPattern, MediaConvertCreateJob.SUPPORTED_INTEGRATION_PATTERNS);
51+
52+
cdk.requireProperty(props.createJobRequest, 'Role', this);
53+
cdk.requireProperty(props.createJobRequest, 'Settings', this);
54+
55+
this.taskPolicies = this.renderPolicyStatements();
56+
}
57+
58+
private renderPolicyStatements(): iam.PolicyStatement[] {
59+
const policyStatements = [
60+
new iam.PolicyStatement({
61+
actions: ['iam:PassRole'],
62+
resources: [this.props.createJobRequest.Role],
63+
conditions: {
64+
StringLike: { 'iam:PassedToService': 'mediaconvert.amazonaws.com' },
65+
},
66+
}),
67+
new iam.PolicyStatement({
68+
actions: ['mediaconvert:CreateJob'],
69+
resources: ['*'],
70+
}),
71+
];
72+
73+
if (this.props.integrationPattern == sfn.IntegrationPattern.RUN_JOB) {
74+
policyStatements.push(
75+
new iam.PolicyStatement({
76+
actions: ['mediaconvert:GetJob', 'mediaconvert:CancelJob'],
77+
resources: ['*'],
78+
}),
79+
);
80+
policyStatements.push(
81+
new iam.PolicyStatement({
82+
actions: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'],
83+
resources: [
84+
Stack.of(this).formatArn({
85+
service: 'events',
86+
resource: 'rule',
87+
resourceName: 'StepFunctionsGetEventsForMediaConvertJobRule',
88+
}),
89+
],
90+
}),
91+
);
92+
}
93+
94+
return policyStatements;
95+
}
96+
97+
/**
98+
* Provides the MediaConvert CreateJob Service Integration Task Configuration
99+
*
100+
* @internal
101+
*/
102+
protected _renderTask(): any {
103+
return {
104+
Resource: integrationResourceArn('mediaconvert', 'createJob', this.props.integrationPattern),
105+
Parameters: this.props.createJobRequest,
106+
};
107+
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
import { Match, Template } from '../../../assertions';
2+
import * as sfn from '../../../aws-stepfunctions';
3+
import * as cdk from '../../../core';
4+
import { MediaConvertCreateJob } from '../../lib';
5+
6+
let stack: cdk.Stack;
7+
8+
beforeEach(() => {
9+
stack = new cdk.Stack();
10+
});
11+
12+
describe('MediaConvert Create Job', () => {
13+
14+
test('REQUEST_RESPONSE Integration Pattern', () => {
15+
// WHEN
16+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
17+
createJobRequest: {
18+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
19+
Settings: {
20+
OutputGroups: [],
21+
Inputs: [],
22+
},
23+
},
24+
});
25+
26+
// THEN
27+
expect(stack.resolve(task.toStateJson())).toEqual({
28+
Type: 'Task',
29+
Resource: {
30+
'Fn::Join': [
31+
'',
32+
[
33+
'arn:',
34+
{
35+
Ref: 'AWS::Partition',
36+
},
37+
':states:::mediaconvert:createJob',
38+
],
39+
],
40+
},
41+
End: true,
42+
Parameters: {
43+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
44+
Settings: {
45+
OutputGroups: [],
46+
Inputs: [],
47+
},
48+
},
49+
});
50+
});
51+
52+
test('RUN_JOB Integration Pattern', () => {
53+
// WHEN
54+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
55+
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
56+
createJobRequest: {
57+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
58+
Settings: {
59+
OutputGroups: [],
60+
Inputs: [],
61+
},
62+
},
63+
});
64+
65+
// THEN
66+
expect(stack.resolve(task.toStateJson())).toEqual({
67+
Type: 'Task',
68+
Resource: {
69+
'Fn::Join': [
70+
'',
71+
[
72+
'arn:',
73+
{
74+
Ref: 'AWS::Partition',
75+
},
76+
':states:::mediaconvert:createJob.sync',
77+
],
78+
],
79+
},
80+
End: true,
81+
Parameters: {
82+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
83+
Settings: {
84+
OutputGroups: [],
85+
Inputs: [],
86+
},
87+
},
88+
});
89+
});
90+
91+
test('Fails on Unsupported Integration Pattern', () => {
92+
expect(() => {
93+
// WHEN
94+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
95+
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
96+
createJobRequest: {
97+
Settings: {
98+
OutputGroups: [],
99+
Inputs: [],
100+
},
101+
},
102+
});
103+
// THEN
104+
}).toThrow(/Unsupported service integration pattern. Supported Patterns: REQUEST_RESPONSE,RUN_JOB. Received: WAIT_FOR_TASK_TOKEN/);
105+
});
106+
107+
test('Fails on role not specified', () => {
108+
expect(() => {
109+
// WHEN
110+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
111+
createJobRequest: {
112+
Settings: {
113+
OutputGroups: [],
114+
Inputs: [],
115+
},
116+
},
117+
});
118+
// THEN
119+
}).toThrow(/Default\/MediaConvertCreateJob is missing required property: Role/);
120+
});
121+
122+
test('Fails on settings not specified', () => {
123+
expect(() => {
124+
// WHEN
125+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
126+
createJobRequest: {
127+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
128+
},
129+
});
130+
// THEN
131+
}).toThrow(/Default\/MediaConvertCreateJob is missing required property: Settings/);
132+
});
133+
134+
test('Required Policy statements are generated in REQUEST_RESPONSE Integration', () => {
135+
// WHEN
136+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
137+
createJobRequest: {
138+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
139+
Settings: {
140+
OutputGroups: [],
141+
Inputs: [],
142+
},
143+
},
144+
});
145+
146+
new sfn.StateMachine(stack, 'StateMachine', {
147+
definitionBody: sfn.DefinitionBody.fromChainable(task),
148+
});
149+
150+
// THEN
151+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
152+
PolicyDocument: Match.objectLike({
153+
Statement: Match.arrayWith([
154+
{
155+
Action: 'iam:PassRole',
156+
Effect: 'Allow',
157+
Resource: 'arn:aws:iam::123456789012:role/MediaConvertRole',
158+
Condition: {
159+
StringLike: {
160+
'iam:PassedToService': 'mediaconvert.amazonaws.com',
161+
},
162+
},
163+
},
164+
{
165+
Action: 'mediaconvert:CreateJob',
166+
Effect: 'Allow',
167+
Resource: '*',
168+
},
169+
]),
170+
}),
171+
});
172+
});
173+
174+
test('Required Policy statements are generated in RUN_JOB Integration', () => {
175+
// WHEN
176+
const task = new MediaConvertCreateJob(stack, 'MediaConvertCreateJob', {
177+
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
178+
createJobRequest: {
179+
Role: 'arn:aws:iam::123456789012:role/MediaConvertRole',
180+
Settings: {
181+
OutputGroups: [],
182+
Inputs: [],
183+
},
184+
},
185+
});
186+
187+
new sfn.StateMachine(stack, 'StateMachine', {
188+
definitionBody: sfn.DefinitionBody.fromChainable(task),
189+
});
190+
191+
// THEN
192+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
193+
PolicyDocument: Match.objectLike({
194+
Statement: Match.arrayWith([
195+
{
196+
Action: 'iam:PassRole',
197+
Effect: 'Allow',
198+
Resource: 'arn:aws:iam::123456789012:role/MediaConvertRole',
199+
Condition: {
200+
StringLike: {
201+
'iam:PassedToService': 'mediaconvert.amazonaws.com',
202+
},
203+
},
204+
},
205+
{
206+
Action: 'mediaconvert:CreateJob',
207+
Effect: 'Allow',
208+
Resource: '*',
209+
},
210+
{
211+
Action: ['mediaconvert:GetJob', 'mediaconvert:CancelJob'],
212+
Effect: 'Allow',
213+
Resource: '*',
214+
},
215+
{
216+
Action: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'],
217+
Effect: 'Allow',
218+
Resource: {
219+
'Fn::Join': [
220+
'',
221+
[
222+
'arn:',
223+
{
224+
Ref: 'AWS::Partition',
225+
},
226+
':events:',
227+
{
228+
Ref: 'AWS::Region',
229+
},
230+
':',
231+
{
232+
Ref: 'AWS::AccountId',
233+
},
234+
':rule/StepFunctionsGetEventsForMediaConvertJobRule',
235+
],
236+
],
237+
},
238+
},
239+
]),
240+
}),
241+
});
242+
});
243+
});

0 commit comments

Comments
 (0)
Please sign in to comment.