|
1 | 1 | import { NetworkMode } from '@aws-cdk/aws-ecs'; |
2 | 2 | import { Role, ServicePrincipal, ManagedPolicy, PolicyStatement, Effect, IRole } from '@aws-cdk/aws-iam'; |
3 | 3 | import { Construct } from '@aws-cdk/core'; |
4 | | -import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId, PhysicalResourceIdReference } from '@aws-cdk/custom-resources'; |
| 4 | +import { AwsCustomResource, AwsCustomResourcePolicy, AwsSdkCall, PhysicalResourceId, PhysicalResourceIdReference } from '@aws-cdk/custom-resources'; |
5 | 5 |
|
6 | 6 | export interface IDummyTaskDefinition { |
7 | 7 | readonly executionRole: IRole; |
@@ -63,41 +63,46 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti |
63 | 63 | this.containerName = props.containerName ?? 'sample-website'; |
64 | 64 | this.containerPort = props.containerPort ?? 80; |
65 | 65 |
|
66 | | - const taskDefinition = new AwsCustomResource(this, 'DummyTaskDefinition', { |
67 | | - resourceType: 'Custom::DummyTaskDefinition', |
68 | | - onCreate: { |
69 | | - service: 'ECS', |
70 | | - action: 'registerTaskDefinition', |
71 | | - parameters: { |
72 | | - requiresCompatibilities: ['FARGATE'], |
73 | | - family: this.family, |
74 | | - executionRoleArn: this.executionRole.roleArn, |
75 | | - networkMode: NetworkMode.AWS_VPC, |
76 | | - cpu: '256', |
77 | | - memory: '512', |
78 | | - containerDefinitions: [ |
79 | | - { |
80 | | - name: this.containerName, |
81 | | - image: props.image, |
82 | | - portMappings: [ |
83 | | - { |
84 | | - hostPort: this.containerPort, |
85 | | - protocol: 'tcp', |
86 | | - containerPort: this.containerPort, |
87 | | - }, |
88 | | - ], |
89 | | - }, |
90 | | - ], |
91 | | - }, |
92 | | - physicalResourceId: PhysicalResourceId.fromResponse('taskDefinition.taskDefinitionArn'), |
| 66 | + const registerTaskDefinition: AwsSdkCall = { |
| 67 | + service: 'ECS', |
| 68 | + action: 'registerTaskDefinition', |
| 69 | + parameters: { |
| 70 | + requiresCompatibilities: ['FARGATE'], |
| 71 | + family: this.family, |
| 72 | + executionRoleArn: this.executionRole.roleArn, |
| 73 | + networkMode: NetworkMode.AWS_VPC, |
| 74 | + cpu: '256', |
| 75 | + memory: '512', |
| 76 | + containerDefinitions: [ |
| 77 | + { |
| 78 | + name: this.containerName, |
| 79 | + image: props.image, |
| 80 | + portMappings: [ |
| 81 | + { |
| 82 | + hostPort: this.containerPort, |
| 83 | + protocol: 'tcp', |
| 84 | + containerPort: this.containerPort, |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ], |
93 | 89 | }, |
94 | | - onDelete: { |
95 | | - service: 'ECS', |
96 | | - action: 'deregisterTaskDefinition', |
97 | | - parameters: { |
98 | | - taskDefinition: new PhysicalResourceIdReference(), |
99 | | - }, |
| 90 | + physicalResourceId: PhysicalResourceId.fromResponse('taskDefinition.taskDefinitionArn'), |
| 91 | + }; |
| 92 | + |
| 93 | + const deregisterTaskDefinition: AwsSdkCall = { |
| 94 | + service: 'ECS', |
| 95 | + action: 'deregisterTaskDefinition', |
| 96 | + parameters: { |
| 97 | + taskDefinition: new PhysicalResourceIdReference(), |
100 | 98 | }, |
| 99 | + }; |
| 100 | + |
| 101 | + const taskDefinition = new AwsCustomResource(this, 'DummyTaskDefinition', { |
| 102 | + resourceType: 'Custom::DummyTaskDefinition', |
| 103 | + onCreate: registerTaskDefinition, |
| 104 | + onUpdate: registerTaskDefinition, |
| 105 | + onDelete: deregisterTaskDefinition, |
101 | 106 | policy: AwsCustomResourcePolicy.fromStatements([ |
102 | 107 | new PolicyStatement({ |
103 | 108 | effect: Effect.ALLOW, |
|
0 commit comments