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

chore: forward merge 'master' into 'v2-main' #15042

Merged
merged 7 commits into from
Jun 14, 2021
41 changes: 41 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,44 @@ new QueueProcessingFargateService(stack, 'QueueProcessingService', {
image: new ecs.AssetImage(path.join(__dirname, '..', 'sqs-reader')),
});
```

### Deploy application and metrics sidecar

The following is an example of deploying an application along with a metrics sidecar container that utilizes `dockerLabels` for discovery:

```ts
const service = new ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
vpc,
desiredCount: 1,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
dockerLabels: {
'application.label.one': 'first_label'
'application.label.two': 'second_label'
}
});

service.taskDefinition.addContainer('Sidecar', {
image: ContainerImage.fromRegistry('example/metrics-sidecar')
}
```

### Select specific load balancer name ApplicationLoadBalancedFargateService

```ts
const loadBalancedFargateService = new ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 1024,
desiredCount: 1,
cpu: 512,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
vpcSubnets: {
subnets: [ec2.Subnet.fromSubnetId(stack, 'subnet', 'VpcISOLATEDSubnet1Subnet80F07FA0')],
},
loadBalancerName: 'application-lb-name',
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export interface ApplicationLoadBalancedServiceBaseProps {
*/
readonly circuitBreaker?: DeploymentCircuitBreaker;

/**
* Name of the load balancer
*
* @default - Automatically generated name.
*/
readonly loadBalancerName?: string;

}

export interface ApplicationLoadBalancedTaskImageOptions {
Expand Down Expand Up @@ -321,6 +328,13 @@ export interface ApplicationLoadBalancedTaskImageOptions {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -400,6 +414,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {

const lbProps = {
vpc: this.cluster.vpc,
loadBalancerName: props.loadBalancerName,
internetFacing,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ export interface ApplicationLoadBalancedTaskImageProps {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ export interface NetworkLoadBalancedTaskImageOptions {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ export interface NetworkLoadBalancedTaskImageProps {
* @default - Automatically generated name.
*/
readonly family?: string;

/**
* A key/value map of labels to add to the container.
*
* @default - No labels.
*/
readonly dockerLabels?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -448,4 +455,4 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends Construct {
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: this.logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -151,4 +152,4 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip
cloudMapOptions: props.cloudMapOptions,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: this.logDriver,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -151,4 +152,4 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget
cloudMapOptions: props.cloudMapOptions,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
logging: logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu
logging: this.logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -184,4 +185,4 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu
platformVersion: props.platformVersion,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
logging: logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa
logging: this.logDriver,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
});
if (taskImageOptions.containerPorts) {
for (const containerPort of taskImageOptions.containerPorts) {
Expand Down Expand Up @@ -184,4 +185,4 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa
platformVersion: props.platformVersion,
});
}
}
}
12 changes: 11 additions & 1 deletion packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
desiredCount: 3,
Expand Down Expand Up @@ -214,6 +215,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
ExecutionRoleArn: {
Expand Down Expand Up @@ -967,6 +972,7 @@ export = {
taskRole: new Role(stack, 'TaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
}),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
cpu: 256,
desiredCount: 3,
Expand Down Expand Up @@ -1079,6 +1085,10 @@ export = {
Protocol: 'tcp',
},
],
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
ExecutionRoleArn: {
Expand Down Expand Up @@ -1532,4 +1542,4 @@ export = {
test.done();
},
},
};
};
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export = {
TEST_ENVIRONMENT_VARIABLE1: 'test environment variable 1 value',
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
desiredCount: 2,
});
Expand All @@ -54,6 +55,10 @@ export = {
},
],
Memory: 1024,
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));
Expand Down Expand Up @@ -389,6 +394,7 @@ export = {
TEST_ENVIRONMENT_VARIABLE1: 'test environment variable 1 value',
TEST_ENVIRONMENT_VARIABLE2: 'test environment variable 2 value',
},
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
desiredCount: 2,
});
Expand Down Expand Up @@ -416,6 +422,10 @@ export = {
'awslogs-region': { Ref: 'AWS::Region' },
},
},
DockerLabels: {
label1: 'labelValue1',
label2: 'labelValue2',
},
},
],
}));
Expand Down
Loading