This creates a service using the EC2 launch type on an ECS cluster.
import { Ec2Service } from 'aws-cdk-lib/aws-ecs';Or use the module namespace:
import * as ecs from 'aws-cdk-lib/aws-ecs';
// ecs.Ec2ServiceConfiguration passed to the constructor as Ec2ServiceProps.
taskDefinitionRequiredTaskDefinitionThe task definition to use for tasks in the service. [disable-awslint:ref-via-interface]
assignPublicIpOptionalbooleanSpecifies 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
availabilityZoneRebalancingOptionalAvailabilityZoneRebalancingWhether 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
daemonOptionalbooleanSpecifies 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
placementConstraintsOptionalPlacementConstraint[]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.
placementStrategiesOptionalPlacementStrategy[]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.
securityGroupsOptionalISecurityGroup[]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.
vpcSubnetsOptionalSubnetSelectionThe 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.
BaseServiceOptionsclusterRequiredinherited from BaseServiceOptionsIClusterThe name of the cluster that hosts the service.
bakeTimeOptionalinherited from BaseServiceOptionsDurationbake time minutes for service.
Default: - none
canaryConfigurationOptionalinherited from BaseServiceOptionsTrafficShiftConfigConfiguration for canary deployment strategy. Only valid when deploymentStrategy is set to CANARY.
Default: - no canary configuration
capacityProviderStrategiesOptionalinherited from BaseServiceOptionsCapacityProviderStrategy[]A list of Capacity Provider strategies used to place a service.
Default: - undefined
circuitBreakerOptionalinherited from BaseServiceOptionsDeploymentCircuitBreakerWhether to enable the deployment circuit breaker. If this property is defined, circuit breaker will be implicitly enabled.
Default: - disabled
cloudMapOptionsOptionalinherited from BaseServiceOptionsCloudMapOptionsThe options for configuring an Amazon ECS service to use service discovery.
Default: - AWS Cloud Map service discovery is not enabled.
deploymentAlarmsOptionalinherited from BaseServiceOptionsDeploymentAlarmConfigThe 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 BaseServiceOptionsDeploymentControllerSpecifies 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 BaseServiceOptionsDeploymentStrategyThe deployment strategy to use for the service.
Default: ROLLING
desiredCountOptionalinherited from BaseServiceOptionsnumberThe 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 BaseServiceOptionsbooleanSpecifies 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 BaseServiceOptionsbooleanWhether to enable the ability to execute into a container.
Default: - undefined
healthCheckGracePeriodOptionalinherited from BaseServiceOptionsDurationThe 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 BaseServiceOptionsIDeploymentLifecycleHookTarget[]The lifecycle hooks to execute during deployment stages.
Default: - none;
linearConfigurationOptionalinherited from BaseServiceOptionsTrafficShiftConfigConfiguration for linear deployment strategy. Only valid when deploymentStrategy is set to LINEAR.
Default: - no linear configuration
maxHealthyPercentOptionalinherited from BaseServiceOptionsnumberThe 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 BaseServiceOptionsnumberThe 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 BaseServiceOptionsPropagatedTagSourceSpecifies 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 BaseServiceOptionsServiceConnectPropsConfiguration 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 BaseServiceOptionsstringThe name of the service.
Default: - CloudFormation-generated name.
taskDefinitionRevisionOptionalinherited from BaseServiceOptionsTaskDefinitionRevisionRevision 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 BaseServiceOptionsServiceManagedVolume[]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
Everything you need to know about Amazon ECS on one page. HD quality, print-friendly.
Download Free Infographicaws-ecs