AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

Ec2Service

This creates a service using the EC2 launch type on an ECS cluster.

Import

import { Ec2Service } from 'aws-cdk-lib/aws-ecs';

Or use the module namespace:

import * as ecs from 'aws-cdk-lib/aws-ecs';
// ecs.Ec2Service

Properties

Configuration passed to the constructor as Ec2ServiceProps.

taskDefinitionRequired
TaskDefinition

The task definition to use for tasks in the service. [disable-awslint:ref-via-interface]

assignPublicIpOptional
boolean

Specifies whether the task's elastic network interface receives a public IP address. If true, each task will receive a public IP address. This property is only used for tasks that use the awsvpc network mode.

Default: false

availabilityZoneRebalancingOptional
AvailabilityZoneRebalancing

Whether to use Availability Zone rebalancing for the service. If enabled: `maxHealthyPercent` must be greater than 100; `daemon` must be false; if there are any `placementStrategies`, the first must be "spread across Availability Zones"; there must be no `placementConstraints` using `attribute:ecs.availability-zone`, and the service must not be a target of a Classic Load Balancer.

Default: AvailabilityZoneRebalancing.ENABLED

daemonOptional
boolean

Specifies whether the service will use the daemon scheduling strategy. If true, the service scheduler deploys exactly one task on each container instance in your cluster. When you are using this strategy, do not specify a desired number of tasks or any task placement strategies.

Default: false

placementConstraintsOptional
PlacementConstraint[]

The placement constraints to use for tasks in the service. For more information, see [Amazon ECS Task Placement Constraints](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-constraints.html).

Default: - No constraints.

placementStrategiesOptional
PlacementStrategy[]

The placement strategies to use for tasks in the service. For more information, see [Amazon ECS Task Placement Strategies](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement-strategies.html).

Default: - No strategies.

securityGroupsOptional
ISecurityGroup[]

The security groups to associate with the service. If you do not specify a security group, a new security group is created. This property is only used for tasks that use the awsvpc network mode.

Default: - A new security group is created.

vpcSubnetsOptional
SubnetSelection

The subnets to associate with the service. This property is only used for tasks that use the awsvpc network mode.

Default: - Public subnets if `assignPublicIp` is set, otherwise the first available one of Private, Isolated, Public, in that order.

22 properties inherited from BaseServiceOptions
clusterRequiredinherited from BaseServiceOptions
ICluster

The name of the cluster that hosts the service.

bakeTimeOptionalinherited from BaseServiceOptions
Duration

bake time minutes for service.

Default: - none

canaryConfigurationOptionalinherited from BaseServiceOptions
TrafficShiftConfig

Configuration for canary deployment strategy. Only valid when deploymentStrategy is set to CANARY.

Default: - no canary configuration

capacityProviderStrategiesOptionalinherited from BaseServiceOptions
CapacityProviderStrategy[]

A list of Capacity Provider strategies used to place a service.

Default: - undefined

circuitBreakerOptionalinherited from BaseServiceOptions
DeploymentCircuitBreaker

Whether to enable the deployment circuit breaker. If this property is defined, circuit breaker will be implicitly enabled.

Default: - disabled

cloudMapOptionsOptionalinherited from BaseServiceOptions
CloudMapOptions

The options for configuring an Amazon ECS service to use service discovery.

Default: - AWS Cloud Map service discovery is not enabled.

deploymentAlarmsOptionalinherited from BaseServiceOptions
DeploymentAlarmConfig

The alarm(s) to monitor during deployment, and behavior to apply if at least one enters a state of alarm during the deployment or bake time.

Default: - No alarms will be monitored during deployment.

deploymentControllerOptionalinherited from BaseServiceOptions
DeploymentController

Specifies which deployment controller to use for the service. For more information, see [Amazon ECS Deployment Types](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html)

Default: - Rolling update (ECS)

deploymentStrategyOptionalinherited from BaseServiceOptions
DeploymentStrategy

The deployment strategy to use for the service.

Default: ROLLING

desiredCountOptionalinherited from BaseServiceOptions
number

The desired number of instantiations of the task definition to keep running on the service.

Default: - When creating the service, default is 1; when updating the service, default uses the current task number.

enableECSManagedTagsOptionalinherited from BaseServiceOptions
boolean

Specifies whether to enable Amazon ECS managed tags for the tasks within the service. For more information, see [Tagging Your Amazon ECS Resources](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html)

Default: false

enableExecuteCommandOptionalinherited from BaseServiceOptions
boolean

Whether to enable the ability to execute into a container.

Default: - undefined

healthCheckGracePeriodOptionalinherited from BaseServiceOptions
Duration

The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy Elastic Load Balancing target health checks after a task has first started.

Default: - defaults to 60 seconds if at least one load balancer is in-use and it is not already set

lifecycleHooksOptionalinherited from BaseServiceOptions
IDeploymentLifecycleHookTarget[]

The lifecycle hooks to execute during deployment stages.

Default: - none;

linearConfigurationOptionalinherited from BaseServiceOptions
TrafficShiftConfig

Configuration for linear deployment strategy. Only valid when deploymentStrategy is set to LINEAR.

Default: - no linear configuration

maxHealthyPercentOptionalinherited from BaseServiceOptions
number

The maximum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that can run in a service during a deployment.

Default: - 100 if daemon, otherwise 200

minHealthyPercentOptionalinherited from BaseServiceOptions
number

The minimum number of tasks, specified as a percentage of the Amazon ECS service's DesiredCount value, that must continue to run and remain healthy during a deployment.

Default: - 0 if daemon, otherwise 50

propagateTagsOptionalinherited from BaseServiceOptions
PropagatedTagSource

Specifies whether to propagate the tags from the task definition or the service to the tasks in the service. Valid values are: PropagatedTagSource.SERVICE, PropagatedTagSource.TASK_DEFINITION or PropagatedTagSource.NONE

Default: PropagatedTagSource.NONE

serviceConnectConfigurationOptionalinherited from BaseServiceOptions
ServiceConnectProps

Configuration for Service Connect.

Default: No ports are advertised via Service Connect on this service, and the service cannot make requests to other services via Service Connect.

serviceNameOptionalinherited from BaseServiceOptions
string

The name of the service.

Default: - CloudFormation-generated name.

taskDefinitionRevisionOptionalinherited from BaseServiceOptions
TaskDefinitionRevision

Revision number for the task definition or `latest` to use the latest active task revision.

Default: - Uses the revision of the passed task definition deployed by CloudFormation

volumeConfigurationsOptionalinherited from BaseServiceOptions
ServiceManagedVolume[]

Configuration details for a volume used by the service. This allows you to specify details about the EBS volume that can be attached to ECS tasks.

Default: - undefined

Get the Amazon ECS Cheat Sheet

Everything you need to know about Amazon ECS on one page. HD quality, print-friendly.

Download Free Infographic