Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
maxCapacity: 3
});
// Name service
const nameTaskDefinition = new ecs.Ec2TaskDefinition(this, 'name-task-definition', {});
const nameContainer = nameTaskDefinition.addContainer('name', {
image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
memoryLimitMiB: 128
});
nameContainer.addPortMappings({
containerPort: 3000
});
const nameService = new ecs.Ec2Service(this, 'name-service', {
cluster: cluster,
desiredCount: 2,
taskDefinition: nameTaskDefinition
});
// Greeting service
const greetingTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeting-task-definition', {});
const greetingContainer = greetingTaskDefinition.addContainer('greeting', {
image: ecs.ContainerImage.fromRegistry('nathanpeck/greeting'),
memoryLimitMiB: 128
});
greetingContainer.addPortMappings({
containerPort: 3000
});
taskDefinition: nameTaskDefinition
});
// Greeting service
const greetingTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeting-task-definition', {});
const greetingContainer = greetingTaskDefinition.addContainer('greeting', {
image: ecs.ContainerImage.fromRegistry('nathanpeck/greeting'),
memoryLimitMiB: 128
});
greetingContainer.addPortMappings({
containerPort: 3000
});
const greetingService = new ecs.Ec2Service(this, 'greeting-service', {
cluster: cluster,
desiredCount: 2,
taskDefinition: greetingTaskDefinition
});
// Internal load balancer for the backend services
const internalLB = new elbv2.ApplicationLoadBalancer(this, 'internal', {
vpc: vpc,
internetFacing: false
});
const internalListener = internalLB.addListener('PublicListener', { port: 80, open: true });
internalListener.addTargetGroups('default', {
targetGroups: [new elbv2.ApplicationTargetGroup(this, 'default', {
vpc: vpc,
const greeterTaskDefinition = new ecs.Ec2TaskDefinition(this, 'greeter-task-definition', {});
const greeterContainer = greeterTaskDefinition.addContainer('greeter', {
image: ecs.ContainerImage.fromRegistry('nathanpeck/greeter'),
memoryLimitMiB: 128,
environment: {
GREETING_URL: 'http://' + internalLB.loadBalancerDnsName + '/greeting',
NAME_URL: 'http://' + internalLB.loadBalancerDnsName + '/name'
}
});
greeterContainer.addPortMappings({
containerPort: 3000
});
const greeterService = new ecs.Ec2Service(this, 'greeter-service', {
cluster: cluster,
desiredCount: 2,
taskDefinition: greeterTaskDefinition
});
// Internet facing load balancer for the frontend services
const externalLB = new elbv2.ApplicationLoadBalancer(this, 'external', {
vpc: vpc,
internetFacing: true
});
const externalListener = externalLB.addListener('PublicListener', { port: 80, open: true });
externalListener.addTargets('greeter', {
port: 80,
targets: [greeterService]
// Create a Task Definition for the container to start
this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef');
this.taskDefinition.addContainer('QueueProcessingContainer', {
image: props.image,
memoryLimitMiB: props.memoryLimitMiB,
memoryReservationMiB: props.memoryReservationMiB,
cpu: props.cpu,
command: props.command,
environment: this.environment,
secrets: this.secrets,
logging: this.logDriver
});
// Create an ECS service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
this.service = new Ec2Service(this, 'QueueProcessingService', {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition: this.taskDefinition,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
});
this.configureAutoscalingForService(this.service);
}
}
image: taskImageOptions.image,
cpu: props.cpu,
memoryLimitMiB: props.memoryLimitMiB,
memoryReservationMiB: props.memoryReservationMiB,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80
});
} else {
throw new Error('You must specify one of: taskDefinition or image');
}
this.service = new Ec2Service(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition: this.taskDefinition,
assignPublicIp: false,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
});
this.addServiceAsTarget(this.service);
}
}
image: taskImageOptions.image,
cpu: props.cpu,
memoryLimitMiB: props.memoryLimitMiB,
memoryReservationMiB: props.memoryReservationMiB,
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
logging: logDriver,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80
});
} else {
throw new Error('You must specify one of: taskDefinition or image');
}
this.service = new Ec2Service(this, "Service", {
cluster: this.cluster,
desiredCount: this.desiredCount,
taskDefinition: this.taskDefinition,
assignPublicIp: false,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
});
this.addServiceAsTarget(this.service);
}
}