Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stepfunctions-tasks): add revision number #24226

Merged
merged 22 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
38eaff6
[add] can specify revision number
westhouseK Feb 19, 2023
bd7fee7
Merge branch 'main' into main
westhouseK Feb 19, 2023
df41905
[fix] fix readme and snapshot
westhouseK Feb 19, 2023
0970af0
Merge branch 'main' of https://github.com/westhouseK/aws-cdk
westhouseK Feb 19, 2023
9040f65
[fix] fix integration test
westhouseK Feb 19, 2023
2943ac9
[fix] comment
westhouseK Feb 19, 2023
1a0aa74
Merge branch 'main' into main
westhouseK Feb 20, 2023
b862611
Merge remote-tracking branch 'upstream/main'
westhouseK Feb 21, 2023
bab2531
Merge branch 'main' of https://github.com/westhouseK/aws-cdk
westhouseK Feb 21, 2023
4a62583
Merge branch 'main' into main
westhouseK Feb 25, 2023
9753cd9
Merge branch 'main' into main
westhouseK Feb 27, 2023
8206f43
[fix] Correction of pointed out points
westhouseK Feb 28, 2023
c5c292c
Merge branch 'main' of https://github.com/westhouseK/aws-cdk
westhouseK Feb 28, 2023
8afa100
chore: asset-staging test always expects 'docker' invocation (#24352)
RomainMuller Feb 27, 2023
71a95f5
fix(ec2): userData in launchTemplate is created automatically when ma…
tmokmss Feb 27, 2023
b68bce3
chore(bootstrap): improve permissions boundary switch message (#24354)
corymhall Feb 27, 2023
700c0ef
feat(eks): add helm flag --skip-crds (#24213)
alexandersperling Feb 27, 2023
ac04629
docs(cfnspec): update CloudFormation documentation (#24362)
aws-cdk-automation Feb 28, 2023
5b7e515
[fix] add new line
westhouseK Feb 28, 2023
6df368d
Merge branch 'main' into main
westhouseK Feb 28, 2023
c1b22ad
Merge branch 'main' into main
westhouseK Feb 28, 2023
9020d20
Merge branch 'main' into main
mergify[bot] Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ state machine role's policy. Use it in the case where the call requires more tha
to be executed:

```ts
const detectLabels = new tasks.CallAwsService(stack, 'DetectLabels', {
const detectLabels = new tasks.CallAwsService(this, 'DetectLabels', {
service: 'rekognition',
action: 'detectLabels',
iamResources: ['*'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export interface EcsRunTaskProps extends sfn.TaskStateBaseProps {
*/
readonly taskDefinition: ecs.TaskDefinition;

/**
* The revision number of ECS task definiton family
*
* @default - '$latest'
*/
readonly revisionNumber?: number;

/**
* Container setting overrides
*
Expand Down Expand Up @@ -282,7 +289,7 @@ export class EcsRunTask extends sfn.TaskStateBase implements ec2.IConnectable {
Resource: integrationResourceArn('ecs', 'runTask', this.integrationPattern),
Parameters: sfn.FieldUtils.renderObject({
Cluster: this.props.cluster.clusterArn,
TaskDefinition: this.props.taskDefinition.family,
TaskDefinition: this.props.revisionNumber === undefined ? this.props.taskDefinition.family : `${this.props.taskDefinition.family}:${this.props.revisionNumber.toString()}`,
NetworkConfiguration: this.networkConfiguration,
Overrides: renderOverrides(this.props.containerOverrides),
...this.props.launchTarget.bind(this, { taskDefinition: this.props.taskDefinition, cluster: this.props.cluster }).parameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "30.0.0",
"files": {
"add92abd33bdedcd7447faa84ea0fe330f8f547f3de2b71052511e602a947aa7": {
"e24a1536363f5a0e085f665d59c23d647a03864eb45d88b8d07e2d0d8e285ee1": {
"source": {
"path": "aws-sfn-tasks-ecs-fargate-integ.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "add92abd33bdedcd7447faa84ea0fe330f8f547f3de2b71052511e602a947aa7.json",
"objectKey": "e24a1536363f5a0e085f665d59c23d647a03864eb45d88b8d07e2d0d8e285ee1.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,22 @@
}
}
},
"FargeateTaskSetRevisionNumberSecurityGroup916C9B0B": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber/SecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1"
}
],
"VpcId": {
"Ref": "FargateClusterVpc377E8024"
}
}
},
"StateMachineRoleB840431D": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -775,7 +791,7 @@
"Fn::Join": [
"",
[
"{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"SomeKey\":\"SomeValue\",\"Timeout\":900},\"Next\":\"FargateTask\"},\"FargateTask\":{\"End\":true,\"Type\":\"Task\",\"TimeoutSecondsPath\":\"$.Timeout\",\"Resource\":\"arn:",
"{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"SomeKey\":\"SomeValue\",\"Timeout\":900},\"Next\":\"FargateTask\"},\"FargateTask\":{\"Next\":\"FargeateTaskSetRevisionNumber\",\"Type\":\"Task\",\"TimeoutSecondsPath\":\"$.Timeout\",\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
Expand All @@ -801,7 +817,33 @@
"GroupId"
]
},
"\"]}},\"Overrides\":{\"ContainerOverrides\":[{\"Name\":\"TheContainer\",\"Environment\":[{\"Name\":\"SOME_KEY\",\"Value.$\":\"$.SomeKey\"}]}]},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}}}}"
"\"]}},\"Overrides\":{\"ContainerOverrides\":[{\"Name\":\"TheContainer\",\"Environment\":[{\"Name\":\"SOME_KEY\",\"Value.$\":\"$.SomeKey\"}]}]},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}},\"FargeateTaskSetRevisionNumber\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
":states:::ecs:runTask\",\"Parameters\":{\"Cluster\":\"",
{
"Fn::GetAtt": [
"FargateCluster7CCD5F93",
"Arn"
]
},
"\",\"TaskDefinition\":\"awssfntasksecsfargateintegTaskDefD0F4AD10:1\",\"NetworkConfiguration\":{\"AwsvpcConfiguration\":{\"Subnets\":[\"",
{
"Ref": "FargateClusterVpcPrivateSubnet1Subnet9127625F"
},
"\",\"",
{
"Ref": "FargateClusterVpcPrivateSubnet2Subnet307CEE57"
},
"\"],\"SecurityGroups\":[\"",
{
"Fn::GetAtt": [
"FargeateTaskSetRevisionNumberSecurityGroup916C9B0B",
"GroupId"
]
},
"\"]}},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}}}}"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/add92abd33bdedcd7447faa84ea0fe330f8f547f3de2b71052511e602a947aa7.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/e24a1536363f5a0e085f665d59c23d647a03864eb45d88b8d07e2d0d8e285ee1.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -213,6 +213,12 @@
"data": "FargateTaskSecurityGroup0BBB27CB"
}
],
"/aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber/SecurityGroup/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "FargeateTaskSetRevisionNumberSecurityGroup916C9B0B"
}
],
"/aws-sfn-tasks-ecs-fargate-integ/StateMachine/Role/Resource": [
{
"type": "aws:cdk:logicalId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,50 @@
"version": "0.0.0"
}
},
"FargeateTaskSetRevisionNumber": {
"id": "FargeateTaskSetRevisionNumber",
"path": "aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber",
"children": {
"SecurityGroup": {
"id": "SecurityGroup",
"path": "aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber/SecurityGroup",
"children": {
"Resource": {
"id": "Resource",
"path": "aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber/SecurityGroup/Resource",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup",
"aws:cdk:cloudformation:props": {
"groupDescription": "aws-sfn-tasks-ecs-fargate-integ/FargeateTaskSetRevisionNumber/SecurityGroup",
"securityGroupEgress": [
{
"cidrIp": "0.0.0.0/0",
"description": "Allow all outbound traffic by default",
"ipProtocol": "-1"
}
],
"vpcId": {
"Ref": "FargateClusterVpc377E8024"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-ec2.CfnSecurityGroup",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-ec2.SecurityGroup",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-stepfunctions-tasks.EcsRunTask",
"version": "0.0.0"
}
},
"StateMachine": {
"id": "StateMachine",
"path": "aws-sfn-tasks-ecs-fargate-integ/StateMachine",
Expand Down Expand Up @@ -1282,7 +1326,7 @@
"Fn::Join": [
"",
[
"{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"SomeKey\":\"SomeValue\",\"Timeout\":900},\"Next\":\"FargateTask\"},\"FargateTask\":{\"End\":true,\"Type\":\"Task\",\"TimeoutSecondsPath\":\"$.Timeout\",\"Resource\":\"arn:",
"{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"SomeKey\":\"SomeValue\",\"Timeout\":900},\"Next\":\"FargateTask\"},\"FargateTask\":{\"Next\":\"FargeateTaskSetRevisionNumber\",\"Type\":\"Task\",\"TimeoutSecondsPath\":\"$.Timeout\",\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
Expand All @@ -1308,7 +1352,33 @@
"GroupId"
]
},
"\"]}},\"Overrides\":{\"ContainerOverrides\":[{\"Name\":\"TheContainer\",\"Environment\":[{\"Name\":\"SOME_KEY\",\"Value.$\":\"$.SomeKey\"}]}]},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}}}}"
"\"]}},\"Overrides\":{\"ContainerOverrides\":[{\"Name\":\"TheContainer\",\"Environment\":[{\"Name\":\"SOME_KEY\",\"Value.$\":\"$.SomeKey\"}]}]},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}},\"FargeateTaskSetRevisionNumber\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:",
{
"Ref": "AWS::Partition"
},
":states:::ecs:runTask\",\"Parameters\":{\"Cluster\":\"",
{
"Fn::GetAtt": [
"FargateCluster7CCD5F93",
"Arn"
]
},
"\",\"TaskDefinition\":\"awssfntasksecsfargateintegTaskDefD0F4AD10:1\",\"NetworkConfiguration\":{\"AwsvpcConfiguration\":{\"Subnets\":[\"",
{
"Ref": "FargateClusterVpcPrivateSubnet1Subnet9127625F"
},
"\",\"",
{
"Ref": "FargateClusterVpcPrivateSubnet2Subnet307CEE57"
},
"\"],\"SecurityGroups\":[\"",
{
"Fn::GetAtt": [
"FargeateTaskSetRevisionNumberSecurityGroup916C9B0B",
"GroupId"
]
},
"\"]}},\"LaunchType\":\"FARGATE\",\"PlatformVersion\":\"1.4.0\"}}}}"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ const definition = new sfn.Pass(stack, 'Start', {
}),
taskTimeout: sfn.Timeout.at('$.Timeout'),
}),
).next(
new tasks.EcsRunTask(stack, 'FargeateTaskSetRevisionNumber', {
cluster,
taskDefinition,
revisionNumber: 1,
launchTarget: new tasks.EcsFargateLaunchTarget({
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
}),
}),
);

const sm = new sfn.StateMachine(stack, 'StateMachine', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,72 @@ test('Running a task with WAIT_FOR_TASK_TOKEN and task token in environment', ()
taskDefinition,
})).not.toThrow();
});

test('Set revision number of ECS task denition family', () => {
// When
const taskDefinition = new ecs.TaskDefinition(stack, 'TD', {
memoryMiB: '512',
cpu: '256',
compatibility: ecs.Compatibility.FARGATE,
});
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromRegistry('foo/bar'),
memoryLimitMiB: 256,
});
const runTask = new tasks.EcsRunTask(stack, 'task', {
cluster,
taskDefinition: taskDefinition,
revisionNumber: 1,
launchTarget: new tasks.EcsFargateLaunchTarget(),
});

// Then
expect(stack.resolve(runTask.toStateJson())).toEqual(
{
End: true,
Parameters: {
Cluster: {
'Fn::GetAtt': [
'ClusterEB0386A7',
'Arn',
],
},
LaunchType: 'FARGATE',
NetworkConfiguration: {
AwsvpcConfiguration: {
SecurityGroups: [
{
'Fn::GetAtt': [
'taskSecurityGroup28F0D539',
'GroupId',
],
},
],
Subnets: [
{
Ref: 'VpcPrivateSubnet1Subnet536B997A',
},
{
Ref: 'VpcPrivateSubnet2Subnet3788AAA1',
},
],
},
},
TaskDefinition: 'TD:1',
},
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
'Ref': 'AWS::Partition',
},
':states:::ecs:runTask',
],
],
},
Type: 'Task',
},
);
});