Ec2ServiceProps Struct
The properties for defining a service using the EC2 launch type.
Example
declare const vpc: ec2.Vpc;
// Create an ECS cluster
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
// Add capacity to it
cluster.addCapacity('DefaultAutoScalingGroupCapacity', {
instanceType: new ec2.InstanceType("t2.xlarge"),
});
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('DefaultContainer', {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
memoryLimitMiB: 512,
});
// Instantiate an Amazon ECS Service
const ecsService = new ecs.Ec2Service(this, 'Service', {
cluster,
taskDefinition,
minHealthyPercent: 100,
circuitBreaker: {
enable: true,
},
});
Properties
assignPublicIpbooleanassign_public_ipboolassignPublicIpBooleanAssignPublicIpboolAssignPublicIp*bool= false#If true, each task will receive a public IP address.
This property is only used for tasks that use the awsvpc network mode.
availabilityZoneRebalancingAvailabilityZoneRebalancingavailability_zone_rebalancingAvailabilityZoneRebalancingavailabilityZoneRebalancingAvailabilityZoneRebalancingAvailabilityZoneRebalancingAvailabilityZoneRebalancingAvailabilityZoneRebalancingAvailabilityZoneRebalancing= AvailabilityZoneRebalancing.ENAB…#notes · default
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
canaryConfigurationTrafficShiftConfigcanary_configurationTrafficShiftConfigcanaryConfigurationTrafficShiftConfigCanaryConfigurationTrafficShiftConfigCanaryConfigurationTrafficShiftConfig= no canary configuration#Only valid when deploymentStrategy is set to CANARY.
capacityProviderStrategiesCapacityProviderStrategy[]capacity_provider_strategiestyping.List[CapacityProviderStrategy]capacityProviderStrategiesList<CapacityProviderStrategy>CapacityProviderStrategiesCapacityProviderStrategy[]CapacityProviderStrategies*[]CapacityProviderStrategy= undefined#circuitBreakerDeploymentCircuitBreakercircuit_breakerDeploymentCircuitBreakercircuitBreakerDeploymentCircuitBreakerCircuitBreakerDeploymentCircuitBreakerCircuitBreakerDeploymentCircuitBreaker= disabled#If this property is defined, circuit breaker will be implicitly enabled.
cloudMapOptionsCloudMapOptionscloud_map_optionsCloudMapOptionscloudMapOptionsCloudMapOptionsCloudMapOptionsCloudMapOptionsCloudMapOptionsCloudMapOptions= AWS Cloud Map service discovery …#default
Default: AWS Cloud Map service discovery is not enabled.
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.
deploymentAlarmsDeploymentAlarmConfigdeployment_alarmsDeploymentAlarmConfigdeploymentAlarmsDeploymentAlarmConfigDeploymentAlarmsDeploymentAlarmConfigDeploymentAlarmsDeploymentAlarmConfig= No alarms will be monitored duri…#default
Default: No alarms will be monitored during deployment.
deploymentControllerDeploymentControllerdeployment_controllerDeploymentControllerdeploymentControllerDeploymentControllerDeploymentControllerDeploymentControllerDeploymentControllerDeploymentController= Rolling update (ECS)#For more information, see Amazon ECS Deployment Types
deploymentStrategyDeploymentStrategydeployment_strategyDeploymentStrategydeploymentStrategyDeploymentStrategyDeploymentStrategyDeploymentStrategyDeploymentStrategyDeploymentStrategy= ROLLING#desiredCountnumberdesired_countint | floatdesiredCountNumberDesiredCountdoubleDesiredCount*float64= When creating the service, defau…#default
Default: When creating the service, default is 1; when updating the service, default uses the current task number.
enableECSManagedTagsbooleanenable_ecs_managed_tagsboolenableECSManagedTagsBooleanEnableECSManagedTagsboolEnableECSManagedTags*bool= false#For more information, see Tagging Your Amazon ECS Resources
enableExecuteCommandbooleanenable_execute_commandboolenableExecuteCommandBooleanEnableExecuteCommandboolEnableExecuteCommand*bool= undefined#forceNewDeploymentForceNewDeploymentforce_new_deploymentForceNewDeploymentforceNewDeploymentForceNewDeploymentForceNewDeploymentForceNewDeploymentForceNewDeploymentForceNewDeployment= no forced deployment#notes
By default, deployments aren't forced. You can use this option to start a new deployment with no service definition changes. For example, you can update a service's tasks to use a newer Docker image with the same image/tag combination (my_image:latest) or to roll Fargate tasks onto a newer platform version.
This is equivalent to calling the forceNewDeployment() method, but allows you to configure it declaratively at construction time, including the ability to explicitly disable it with enabled: false.
healthCheckGracePeriodDurationhealth_check_grace_periodDurationhealthCheckGracePeriodDurationHealthCheckGracePeriodDurationHealthCheckGracePeriodDuration= defaults to 60 seconds if at lea…#default
Default: defaults to 60 seconds if at least one load balancer is in-use and it is not already set
lifecycleHooksIDeploymentLifecycleHookTarget[]lifecycle_hookstyping.List[IDeploymentLifecycleHookTarget]lifecycleHooksList<IDeploymentLifecycleHookTarget>LifecycleHooksIDeploymentLifecycleHookTarget[]LifecycleHooks*[]IDeploymentLifecycleHookTarget= none;#linearConfigurationTrafficShiftConfiglinear_configurationTrafficShiftConfiglinearConfigurationTrafficShiftConfigLinearConfigurationTrafficShiftConfigLinearConfigurationTrafficShiftConfig= no linear configuration#Only valid when deploymentStrategy is set to LINEAR.
maxHealthyPercentnumbermax_healthy_percentint | floatmaxHealthyPercentNumberMaxHealthyPercentdoubleMaxHealthyPercent*float64= 100 if daemon, otherwise 200#minHealthyPercentnumbermin_healthy_percentint | floatminHealthyPercentNumberMinHealthyPercentdoubleMinHealthyPercent*float64= 0 if daemon, otherwise 50#placementConstraintsPlacementConstraint[]placement_constraintstyping.List[PlacementConstraint]placementConstraintsList<PlacementConstraint>PlacementConstraintsPlacementConstraint[]PlacementConstraints*[]PlacementConstraint= No constraints.#For more information, see Amazon ECS Task Placement Constraints.
placementStrategiesPlacementStrategy[]placement_strategiestyping.List[PlacementStrategy]placementStrategiesList<PlacementStrategy>PlacementStrategiesPlacementStrategy[]PlacementStrategies*[]PlacementStrategy= No strategies.#For more information, see Amazon ECS Task Placement Strategies.
propagateTagsPropagatedTagSourcepropagate_tagsPropagatedTagSourcepropagateTagsPropagatedTagSourcePropagateTagsPropagatedTagSourcePropagateTagsPropagatedTagSource= PropagatedTagSource.NONE#Valid values are: PropagatedTagSource.SERVICE, PropagatedTagSource.TASK_DEFINITION or PropagatedTagSource.NONE
securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGroup= A new security group is created.#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.
serviceConnectConfigurationServiceConnectPropsservice_connect_configurationServiceConnectPropsserviceConnectConfigurationServiceConnectPropsServiceConnectConfigurationServiceConnectPropsServiceConnectConfigurationServiceConnectProps= No ports are advertised via Serv…#default
Default: No ports are advertised via Service Connect on this service, and the service cannot make requests to other services via Service Connect.
serviceNamestringservice_namestrserviceNameStringServiceNamestringServiceName*string= CloudFormation-generated name.#taskDefinitionTaskDefinitiontask_definitionTaskDefinitiontaskDefinitionTaskDefinitionTaskDefinitionTaskDefinitionTaskDefinitionTaskDefinitionrequired#[disable-awslint:ref-via-interface]
taskDefinitionRevisionTaskDefinitionRevisiontask_definition_revisionTaskDefinitionRevisiontaskDefinitionRevisionTaskDefinitionRevisionTaskDefinitionRevisionTaskDefinitionRevisionTaskDefinitionRevisionTaskDefinitionRevision= Uses the revision of the passed …#default
Default: Uses the revision of the passed task definition deployed by CloudFormation
volumeConfigurationsServiceManagedVolume[]volume_configurationstyping.List[ServiceManagedVolume]volumeConfigurationsList<ServiceManagedVolume>VolumeConfigurationsServiceManagedVolume[]VolumeConfigurations*[]ServiceManagedVolume= undefined#This allows you to specify details about the EBS volume that can be attached to ECS tasks.
vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection= Public subnets if `assignPublicI…#This property is only used for tasks that use the awsvpc network mode.
default
Default: Public subnets if assignPublicIp is set, otherwise the first available one of Private, Isolated, Public, in that order.