aws-cdk-lib.aws_ecs.CfnService

class CfnService (construct)

LanguageType name
.NETAmazon.CDK.AWS.ECS.CfnService
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecs#CfnService
Javasoftware.amazon.awscdk.services.ecs.CfnService
Pythonaws_cdk.aws_ecs.CfnService
TypeScript aws-cdk-lib » aws_ecs » CfnService

Implements IConstruct, IDependable, IInspectable

A CloudFormation AWS::ECS::Service.

The AWS::ECS::Service resource creates an Amazon Elastic Container Service (Amazon ECS) service that runs and maintains the requested number of tasks and associated load balancers.

The stack update fails if you change any properties that require replacement and at least one Amazon ECS Service Connect ServiceConnectService is configured. This is because AWS CloudFormation creates the replacement service first, but each ServiceConnectService must have a name that is unique in the namespace. > Starting April 15, 2023, AWS ; will not onboard new customers to Amazon Elastic Inference (EI), and will help current customers migrate their workloads to options that offer better price and performance. After April 15, 2023, new customers will not be able to launch instances with Amazon EI accelerators in Amazon SageMaker, Amazon ECS , or Amazon EC2 . However, customers who have used Amazon EI at least once during the past 30-day period are considered current customers and will be able to continue using the service.

Example

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ecs as ecs } from 'aws-cdk-lib';
const cfnService = new ecs.CfnService(this, 'MyCfnService', /* all optional props */ {
  capacityProviderStrategy: [{
    base: 123,
    capacityProvider: 'capacityProvider',
    weight: 123,
  }],
  cluster: 'cluster',
  deploymentConfiguration: {
    alarms: {
      alarmNames: ['alarmNames'],
      enable: false,
      rollback: false,
    },
    deploymentCircuitBreaker: {
      enable: false,
      rollback: false,
    },
    maximumPercent: 123,
    minimumHealthyPercent: 123,
  },
  deploymentController: {
    type: 'type',
  },
  desiredCount: 123,
  enableEcsManagedTags: false,
  enableExecuteCommand: false,
  healthCheckGracePeriodSeconds: 123,
  launchType: 'launchType',
  loadBalancers: [{
    containerPort: 123,

    // the properties below are optional
    containerName: 'containerName',
    loadBalancerName: 'loadBalancerName',
    targetGroupArn: 'targetGroupArn',
  }],
  networkConfiguration: {
    awsvpcConfiguration: {
      subnets: ['subnets'],

      // the properties below are optional
      assignPublicIp: 'assignPublicIp',
      securityGroups: ['securityGroups'],
    },
  },
  placementConstraints: [{
    type: 'type',

    // the properties below are optional
    expression: 'expression',
  }],
  placementStrategies: [{
    type: 'type',

    // the properties below are optional
    field: 'field',
  }],
  platformVersion: 'platformVersion',
  propagateTags: 'propagateTags',
  role: 'role',
  schedulingStrategy: 'schedulingStrategy',
  serviceConnectConfiguration: {
    enabled: false,

    // the properties below are optional
    logConfiguration: {
      logDriver: 'logDriver',
      options: {
        optionsKey: 'options',
      },
      secretOptions: [{
        name: 'name',
        valueFrom: 'valueFrom',
      }],
    },
    namespace: 'namespace',
    services: [{
      portName: 'portName',

      // the properties below are optional
      clientAliases: [{
        port: 123,

        // the properties below are optional
        dnsName: 'dnsName',
      }],
      discoveryName: 'discoveryName',
      ingressPortOverride: 123,
    }],
  },
  serviceName: 'serviceName',
  serviceRegistries: [{
    containerName: 'containerName',
    containerPort: 123,
    port: 123,
    registryArn: 'registryArn',
  }],
  tags: [{
    key: 'key',
    value: 'value',
  }],
  taskDefinition: 'taskDefinition',
});

Initializer

new CfnService(scope: Construct, id: string, props?: CfnServiceProps)

Parameters

  • scope Construct — - scope in which this resource is defined.
  • id string — - scoped id of the resource.
  • props CfnServiceProps — - resource properties.

Create a new AWS::ECS::Service.

Construct Props

NameTypeDescription
capacityProviderStrategy?IResolvable | IResolvable | CapacityProviderStrategyItemProperty[]The capacity provider strategy to use for the service.
cluster?stringThe short name or full Amazon Resource Name (ARN) of the cluster that you run your service on.
deploymentConfiguration?IResolvable | DeploymentConfigurationPropertyOptional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.
deploymentController?IResolvable | DeploymentControllerPropertyThe deployment controller to use for the service.
desiredCount?numberThe number of instantiations of the specified task definition to place and keep running in your service.
enableEcsManagedTags?boolean | IResolvableSpecifies whether to turn on Amazon ECS managed tags for the tasks within the service.
enableExecuteCommand?boolean | IResolvableDetermines whether the execute command functionality is turned on for the service.
healthCheckGracePeriodSeconds?numberThe 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.
launchType?stringThe launch type on which to run your service.
loadBalancers?IResolvable | IResolvable | LoadBalancerProperty[]A list of load balancer objects to associate with the service.
networkConfiguration?IResolvable | NetworkConfigurationPropertyThe network configuration for the service.
placementConstraints?IResolvable | IResolvable | PlacementConstraintProperty[]An array of placement constraint objects to use for tasks in your service.
placementStrategies?IResolvable | IResolvable | PlacementStrategyProperty[]The placement strategy objects to use for tasks in your service.
platformVersion?stringThe platform version that your tasks in the service are running on.
propagateTags?stringSpecifies whether to propagate the tags from the task definition to the task.
role?stringThe name or full Amazon Resource Name (ARN) of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf.
schedulingStrategy?stringThe scheduling strategy to use for the service. For more information, see Services .
serviceConnectConfiguration?IResolvable | ServiceConnectConfigurationPropertyThe configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace.
serviceName?stringThe name of your service.
serviceRegistries?IResolvable | IResolvable | ServiceRegistryProperty[]The details of the service discovery registry to associate with this service. For more information, see Service discovery .
tags?CfnTag[]The metadata that you apply to the service to help you categorize and organize them.
taskDefinition?stringThe family and revision ( family:revision ) or full ARN of the task definition to run in your service.

capacityProviderStrategy?

Type: IResolvable | IResolvable | CapacityProviderStrategyItemProperty[] (optional)

The capacity provider strategy to use for the service.

If a capacityProviderStrategy is specified, the launchType parameter must be omitted. If no capacityProviderStrategy or launchType is specified, the defaultCapacityProviderStrategy for the cluster is used.

A capacity provider strategy may contain a maximum of 6 capacity providers.


cluster?

Type: string (optional)

The short name or full Amazon Resource Name (ARN) of the cluster that you run your service on.

If you do not specify a cluster, the default cluster is assumed.


deploymentConfiguration?

Type: IResolvable | DeploymentConfigurationProperty (optional)

Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.


deploymentController?

Type: IResolvable | DeploymentControllerProperty (optional)

The deployment controller to use for the service.

If no deployment controller is specified, the default value of ECS is used.


desiredCount?

Type: number (optional)

The number of instantiations of the specified task definition to place and keep running in your service.

For new services, if a desired count is not specified, a default value of 1 is used. When using the DAEMON scheduling strategy, the desired count is not required.

For existing services, if a desired count is not specified, it is omitted from the operation.


enableEcsManagedTags?

Type: boolean | IResolvable (optional)

Specifies whether to turn on Amazon ECS managed tags for the tasks within the service.

For more information, see Tagging your Amazon ECS resources in the Amazon Elastic Container Service Developer Guide .

When you use Amazon ECS managed tags, you need to set the propagateTags request parameter.


enableExecuteCommand?

Type: boolean | IResolvable (optional)

Determines whether the execute command functionality is turned on for the service.

If true , the execute command functionality is turned on for all containers in tasks as part of the service.


healthCheckGracePeriodSeconds?

Type: number (optional)

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.

This is only used when your service is configured to use a load balancer. If your service has a load balancer defined and you don't specify a health check grace period value, the default value of 0 is used.

If you do not use an Elastic Load Balancing, we recommend that you use the startPeriod in the task definition health check parameters. For more information, see Health check .

If your service's tasks take a while to start and respond to Elastic Load Balancing health checks, you can specify a health check grace period of up to 2,147,483,647 seconds (about 69 years). During that time, the Amazon ECS service scheduler ignores health check status. This grace period can prevent the service scheduler from marking tasks as unhealthy and stopping them before they have time to come up.


launchType?

Type: string (optional)

The launch type on which to run your service.

For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide .


loadBalancers?

Type: IResolvable | IResolvable | LoadBalancerProperty[] (optional)

A list of load balancer objects to associate with the service.

If you specify the Role property, LoadBalancers must be specified as well. For information about the number of load balancers that you can specify per service, see Service Load Balancing in the Amazon Elastic Container Service Developer Guide .


networkConfiguration?

Type: IResolvable | NetworkConfigurationProperty (optional)

The network configuration for the service.

This parameter is required for task definitions that use the awsvpc network mode to receive their own elastic network interface, and it is not supported for other network modes. For more information, see Task Networking in the Amazon Elastic Container Service Developer Guide .


placementConstraints?

Type: IResolvable | IResolvable | PlacementConstraintProperty[] (optional)

An array of placement constraint objects to use for tasks in your service.

You can specify a maximum of 10 constraints for each task. This limit includes constraints in the task definition and those specified at runtime.


placementStrategies?

Type: IResolvable | IResolvable | PlacementStrategyProperty[] (optional)

The placement strategy objects to use for tasks in your service.

You can specify a maximum of 5 strategy rules for each service.


platformVersion?

Type: string (optional)

The platform version that your tasks in the service are running on.

A platform version is specified only for tasks using the Fargate launch type. If one isn't specified, the LATEST platform version is used. For more information, see AWS Fargate platform versions in the Amazon Elastic Container Service Developer Guide .


propagateTags?

Type: string (optional)

Specifies whether to propagate the tags from the task definition to the task.

If no value is specified, the tags aren't propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action.

The default is NONE .


role?

Type: string (optional)

The name or full Amazon Resource Name (ARN) of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf.

This parameter is only permitted if you are using a load balancer with your service and your task definition doesn't use the awsvpc network mode. If you specify the role parameter, you must also specify a load balancer object with the loadBalancers parameter.

If your account has already created the Amazon ECS service-linked role, that role is used for your service unless you specify a role here. The service-linked role is required if your task definition uses the awsvpc network mode or if the service is configured to use service discovery, an external deployment controller, multiple target groups, or Elastic Inference accelerators in which case you don't specify a role here. For more information, see Using service-linked roles for Amazon ECS in the Amazon Elastic Container Service Developer Guide .

If your specified role has a path other than / , then you must either specify the full role ARN (this is recommended) or prefix the role name with the path. For example, if a role with the name bar has a path of /foo/ then you would specify /foo/bar as the role name. For more information, see Friendly names and paths in the IAM User Guide .


schedulingStrategy?

Type: string (optional)

The scheduling strategy to use for the service. For more information, see Services .

There are two service scheduler strategies available:

  • REPLICA -The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. This scheduler strategy is required if the service uses the CODE_DEPLOY or EXTERNAL deployment controller types.
  • DAEMON -The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler also evaluates the task placement constraints for running tasks and will stop tasks that don't meet the placement constraints. When you're using this strategy, you don't need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies.

Tasks using the Fargate launch type or the CODE_DEPLOY or EXTERNAL deployment controller types don't support the DAEMON scheduling strategy.


serviceConnectConfiguration?

Type: IResolvable | ServiceConnectConfigurationProperty (optional)

The configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace.

Tasks that run in a namespace can use short names to connect to services in the namespace. Tasks can connect to services across all of the clusters in the namespace. Tasks connect through a managed proxy container that collects logs and metrics for increased visibility. Only the tasks that Amazon ECS services create are supported with Service Connect. For more information, see Service Connect in the Amazon Elastic Container Service Developer Guide .


serviceName?

Type: string (optional)

The name of your service.

Up to 255 letters (uppercase and lowercase), numbers, underscores, and hyphens are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a Region or across multiple Regions.

The stack update fails if you change any properties that require replacement and the ServiceName is configured. This is because AWS CloudFormation creates the replacement service first, but each ServiceName must be unique in the cluster.


serviceRegistries?

Type: IResolvable | IResolvable | ServiceRegistryProperty[] (optional)

The details of the service discovery registry to associate with this service. For more information, see Service discovery .

Each service may be associated with one service registry. Multiple service registries for each service isn't supported.


tags?

Type: CfnTag[] (optional)

The metadata that you apply to the service to help you categorize and organize them.

Each tag consists of a key and an optional value, both of which you define. When a service is deleted, the tags are deleted as well.

The following basic restrictions apply to tags:

  • Maximum number of tags per resource - 50
  • For each resource, each tag key must be unique, and each tag key can have only one value.
  • Maximum key length - 128 Unicode characters in UTF-8
  • Maximum value length - 256 Unicode characters in UTF-8
  • If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
  • Tag keys and values are case-sensitive.
  • Do not use aws: , AWS: , or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for AWS use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.

taskDefinition?

Type: string (optional)

The family and revision ( family:revision ) or full ARN of the task definition to run in your service.

If a revision isn't specified, the latest ACTIVE revision is used.

A task definition must be specified if the service uses either the ECS or CODE_DEPLOY deployment controllers.

For more information about deployment types, see Amazon ECS deployment types .

Properties

NameTypeDescription
attrNamestringThe name of the Amazon ECS service, such as sample-webapp .
attrServiceArnstringNot currently supported in AWS CloudFormation .
cfnOptionsICfnResourceOptionsOptions for this resource, such as condition, update policy etc.
cfnProperties{ [string]: any }
cfnResourceTypestringAWS resource type.
creationStackstring[]
logicalIdstringThe logical ID for this CloudFormation stack element.
nodeNodeThe tree node.
refstringReturn a string that will be resolved to a CloudFormation { Ref } for this element.
stackStackThe stack in which this element is defined.
tagsTagManagerThe metadata that you apply to the service to help you categorize and organize them.
capacityProviderStrategy?IResolvable | IResolvable | CapacityProviderStrategyItemProperty[]The capacity provider strategy to use for the service.
cluster?stringThe short name or full Amazon Resource Name (ARN) of the cluster that you run your service on.
deploymentConfiguration?IResolvable | DeploymentConfigurationPropertyOptional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.
deploymentController?IResolvable | DeploymentControllerPropertyThe deployment controller to use for the service.
desiredCount?numberThe number of instantiations of the specified task definition to place and keep running in your service.
enableEcsManagedTags?boolean | IResolvableSpecifies whether to turn on Amazon ECS managed tags for the tasks within the service.
enableExecuteCommand?boolean | IResolvableDetermines whether the execute command functionality is turned on for the service.
healthCheckGracePeriodSeconds?numberThe 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.
launchType?stringThe launch type on which to run your service.
loadBalancers?IResolvable | IResolvable | LoadBalancerProperty[]A list of load balancer objects to associate with the service.
networkConfiguration?IResolvable | NetworkConfigurationPropertyThe network configuration for the service.
placementConstraints?IResolvable | IResolvable | PlacementConstraintProperty[]An array of placement constraint objects to use for tasks in your service.
placementStrategies?IResolvable | IResolvable | PlacementStrategyProperty[]The placement strategy objects to use for tasks in your service.
platformVersion?stringThe platform version that your tasks in the service are running on.
propagateTags?stringSpecifies whether to propagate the tags from the task definition to the task.
role?stringThe name or full Amazon Resource Name (ARN) of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf.
schedulingStrategy?stringThe scheduling strategy to use for the service. For more information, see Services .
serviceConnectConfiguration?IResolvable | ServiceConnectConfigurationPropertyThe configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace.
serviceName?stringThe name of your service.
serviceRegistries?IResolvable | IResolvable | ServiceRegistryProperty[]The details of the service discovery registry to associate with this service. For more information, see Service discovery .
taskDefinition?stringThe family and revision ( family:revision ) or full ARN of the task definition to run in your service.
static CFN_RESOURCE_TYPE_NAMEstringThe CloudFormation resource type name for this resource class.

attrName

Type: string

The name of the Amazon ECS service, such as sample-webapp .


attrServiceArn

Type: string

Not currently supported in AWS CloudFormation .


cfnOptions

Type: ICfnResourceOptions

Options for this resource, such as condition, update policy etc.


cfnProperties

Type: { [string]: any }


cfnResourceType

Type: string

AWS resource type.


creationStack

Type: string[]


logicalId

Type: string

The logical ID for this CloudFormation stack element.

The logical ID of the element is calculated from the path of the resource node in the construct tree.

To override this value, use overrideLogicalId(newLogicalId).


node

Type: Node

The tree node.


ref

Type: string

Return a string that will be resolved to a CloudFormation { Ref } for this element.

If, by any chance, the intrinsic reference of a resource is not a string, you could coerce it to an IResolvable through Lazy.any({ produce: resource.ref }).


stack

Type: Stack

The stack in which this element is defined.

CfnElements must be defined within a stack scope (directly or indirectly).


tags

Type: TagManager

The metadata that you apply to the service to help you categorize and organize them.

Each tag consists of a key and an optional value, both of which you define. When a service is deleted, the tags are deleted as well.

The following basic restrictions apply to tags:

  • Maximum number of tags per resource - 50
  • For each resource, each tag key must be unique, and each tag key can have only one value.
  • Maximum key length - 128 Unicode characters in UTF-8
  • Maximum value length - 256 Unicode characters in UTF-8
  • If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
  • Tag keys and values are case-sensitive.
  • Do not use aws: , AWS: , or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for AWS use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.

capacityProviderStrategy?

Type: IResolvable | IResolvable | CapacityProviderStrategyItemProperty[] (optional)

The capacity provider strategy to use for the service.

If a capacityProviderStrategy is specified, the launchType parameter must be omitted. If no capacityProviderStrategy or launchType is specified, the defaultCapacityProviderStrategy for the cluster is used.

A capacity provider strategy may contain a maximum of 6 capacity providers.


cluster?

Type: string (optional)

The short name or full Amazon Resource Name (ARN) of the cluster that you run your service on.

If you do not specify a cluster, the default cluster is assumed.


deploymentConfiguration?

Type: IResolvable | DeploymentConfigurationProperty (optional)

Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.


deploymentController?

Type: IResolvable | DeploymentControllerProperty (optional)

The deployment controller to use for the service.

If no deployment controller is specified, the default value of ECS is used.


desiredCount?

Type: number (optional)

The number of instantiations of the specified task definition to place and keep running in your service.

For new services, if a desired count is not specified, a default value of 1 is used. When using the DAEMON scheduling strategy, the desired count is not required.

For existing services, if a desired count is not specified, it is omitted from the operation.


enableEcsManagedTags?

Type: boolean | IResolvable (optional)

Specifies whether to turn on Amazon ECS managed tags for the tasks within the service.

For more information, see Tagging your Amazon ECS resources in the Amazon Elastic Container Service Developer Guide .

When you use Amazon ECS managed tags, you need to set the propagateTags request parameter.


enableExecuteCommand?

Type: boolean | IResolvable (optional)

Determines whether the execute command functionality is turned on for the service.

If true , the execute command functionality is turned on for all containers in tasks as part of the service.


healthCheckGracePeriodSeconds?

Type: number (optional)

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.

This is only used when your service is configured to use a load balancer. If your service has a load balancer defined and you don't specify a health check grace period value, the default value of 0 is used.

If you do not use an Elastic Load Balancing, we recommend that you use the startPeriod in the task definition health check parameters. For more information, see Health check .

If your service's tasks take a while to start and respond to Elastic Load Balancing health checks, you can specify a health check grace period of up to 2,147,483,647 seconds (about 69 years). During that time, the Amazon ECS service scheduler ignores health check status. This grace period can prevent the service scheduler from marking tasks as unhealthy and stopping them before they have time to come up.


launchType?

Type: string (optional)

The launch type on which to run your service.

For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide .


loadBalancers?

Type: IResolvable | IResolvable | LoadBalancerProperty[] (optional)

A list of load balancer objects to associate with the service.

If you specify the Role property, LoadBalancers must be specified as well. For information about the number of load balancers that you can specify per service, see Service Load Balancing in the Amazon Elastic Container Service Developer Guide .


networkConfiguration?

Type: IResolvable | NetworkConfigurationProperty (optional)

The network configuration for the service.

This parameter is required for task definitions that use the awsvpc network mode to receive their own elastic network interface, and it is not supported for other network modes. For more information, see Task Networking in the Amazon Elastic Container Service Developer Guide .


placementConstraints?

Type: IResolvable | IResolvable | PlacementConstraintProperty[] (optional)

An array of placement constraint objects to use for tasks in your service.

You can specify a maximum of 10 constraints for each task. This limit includes constraints in the task definition and those specified at runtime.


placementStrategies?

Type: IResolvable | IResolvable | PlacementStrategyProperty[] (optional)

The placement strategy objects to use for tasks in your service.

You can specify a maximum of 5 strategy rules for each service.


platformVersion?

Type: string (optional)

The platform version that your tasks in the service are running on.

A platform version is specified only for tasks using the Fargate launch type. If one isn't specified, the LATEST platform version is used. For more information, see AWS Fargate platform versions in the Amazon Elastic Container Service Developer Guide .


propagateTags?

Type: string (optional)

Specifies whether to propagate the tags from the task definition to the task.

If no value is specified, the tags aren't propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action.

The default is NONE .


role?

Type: string (optional)

The name or full Amazon Resource Name (ARN) of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf.

This parameter is only permitted if you are using a load balancer with your service and your task definition doesn't use the awsvpc network mode. If you specify the role parameter, you must also specify a load balancer object with the loadBalancers parameter.

If your account has already created the Amazon ECS service-linked role, that role is used for your service unless you specify a role here. The service-linked role is required if your task definition uses the awsvpc network mode or if the service is configured to use service discovery, an external deployment controller, multiple target groups, or Elastic Inference accelerators in which case you don't specify a role here. For more information, see Using service-linked roles for Amazon ECS in the Amazon Elastic Container Service Developer Guide .

If your specified role has a path other than / , then you must either specify the full role ARN (this is recommended) or prefix the role name with the path. For example, if a role with the name bar has a path of /foo/ then you would specify /foo/bar as the role name. For more information, see Friendly names and paths in the IAM User Guide .


schedulingStrategy?

Type: string (optional)

The scheduling strategy to use for the service. For more information, see Services .

There are two service scheduler strategies available:

  • REPLICA -The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. This scheduler strategy is required if the service uses the CODE_DEPLOY or EXTERNAL deployment controller types.
  • DAEMON -The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler also evaluates the task placement constraints for running tasks and will stop tasks that don't meet the placement constraints. When you're using this strategy, you don't need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies.

Tasks using the Fargate launch type or the CODE_DEPLOY or EXTERNAL deployment controller types don't support the DAEMON scheduling strategy.


serviceConnectConfiguration?

Type: IResolvable | ServiceConnectConfigurationProperty (optional)

The configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace.

Tasks that run in a namespace can use short names to connect to services in the namespace. Tasks can connect to services across all of the clusters in the namespace. Tasks connect through a managed proxy container that collects logs and metrics for increased visibility. Only the tasks that Amazon ECS services create are supported with Service Connect. For more information, see Service Connect in the Amazon Elastic Container Service Developer Guide .


serviceName?

Type: string (optional)

The name of your service.

Up to 255 letters (uppercase and lowercase), numbers, underscores, and hyphens are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a Region or across multiple Regions.

The stack update fails if you change any properties that require replacement and the ServiceName is configured. This is because AWS CloudFormation creates the replacement service first, but each ServiceName must be unique in the cluster.


serviceRegistries?

Type: IResolvable | IResolvable | ServiceRegistryProperty[] (optional)

The details of the service discovery registry to associate with this service. For more information, see Service discovery .

Each service may be associated with one service registry. Multiple service registries for each service isn't supported.


taskDefinition?

Type: string (optional)

The family and revision ( family:revision ) or full ARN of the task definition to run in your service.

If a revision isn't specified, the latest ACTIVE revision is used.

A task definition must be specified if the service uses either the ECS or CODE_DEPLOY deployment controllers.

For more information about deployment types, see Amazon ECS deployment types .


static CFN_RESOURCE_TYPE_NAME

Type: string

The CloudFormation resource type name for this resource class.

Methods

NameDescription
addDeletionOverride(path)Syntactic sugar for addOverride(path, undefined).
addDependency(target)Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addDependsOn(target)⚠️Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addMetadata(key, value)Add a value to the CloudFormation Resource Metadata.
addOverride(path, value)Adds an override to the synthesized CloudFormation resource.
addPropertyDeletionOverride(propertyPath)Adds an override that deletes the value of a property from the resource definition.
addPropertyOverride(propertyPath, value)Adds an override to a resource property.
applyRemovalPolicy(policy?, options?)Sets the deletion policy of the resource based on the removal policy specified.
getAtt(attributeName, typeHint?)Returns a token for an runtime attribute of this resource.
getMetadata(key)Retrieve a value value from the CloudFormation Resource Metadata.
inspect(inspector)Examines the CloudFormation resource and discloses attributes.
obtainDependencies()Retrieves an array of resources this resource depends on.
obtainResourceDependencies()Get a shallow copy of dependencies between this resource and other resources in the same stack.
overrideLogicalId(newLogicalId)Overrides the auto-generated logical ID with a specific ID.
removeDependency(target)Indicates that this resource no longer depends on another resource.
replaceDependency(target, newTarget)Replaces one dependency with another.
toString()Returns a string representation of this construct.
protected renderProperties(props)

addDeletionOverride(path)

public addDeletionOverride(path: string): void

Parameters

  • path string — The path of the value to delete.

Syntactic sugar for addOverride(path, undefined).


addDependency(target)

public addDependency(target: CfnResource): void

Parameters

  • target CfnResource

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.


addDependsOn(target)⚠️

public addDependsOn(target: CfnResource): void

⚠️ Deprecated: use addDependency

Parameters

  • target CfnResource

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.


addMetadata(key, value)

public addMetadata(key: string, value: any): void

Parameters

  • key string
  • value any

Add a value to the CloudFormation Resource Metadata.

See also: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)


addOverride(path, value)

public addOverride(path: string, value: any): void

Parameters

  • path string — - The path of the property, you can use dot notation to override values in complex types.
  • value any — - The value.

Adds an override to the synthesized CloudFormation resource.

To add a property override, either use addPropertyOverride or prefix path with "Properties." (i.e. Properties.TopicName).

If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.

To include a literal . in the property name, prefix with a \. In most programming languages you will need to write this as "\\." because the \ itself will need to be escaped.

For example,

cfnResource.addOverride('Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes', ['myattribute']);
cfnResource.addOverride('Properties.GlobalSecondaryIndexes.1.ProjectionType', 'INCLUDE');

would add the overrides

"Properties": {
  "GlobalSecondaryIndexes": [
    {
      "Projection": {
        "NonKeyAttributes": [ "myattribute" ]
        ...
      }
      ...
    },
    {
      "ProjectionType": "INCLUDE"
      ...
    },
  ]
  ...
}

The value argument to addOverride will not be processed or translated in any way. Pass raw JSON values in here with the correct capitalization for CloudFormation. If you pass CDK classes or structs, they will be rendered with lowercased key names, and CloudFormation will reject the template.


addPropertyDeletionOverride(propertyPath)

public addPropertyDeletionOverride(propertyPath: string): void

Parameters

  • propertyPath string — The path to the property.

Adds an override that deletes the value of a property from the resource definition.


addPropertyOverride(propertyPath, value)

public addPropertyOverride(propertyPath: string, value: any): void

Parameters

  • propertyPath string — The path of the property.
  • value any — The value.

Adds an override to a resource property.

Syntactic sugar for addOverride("Properties.<...>", value).


applyRemovalPolicy(policy?, options?)

public applyRemovalPolicy(policy?: RemovalPolicy, options?: RemovalPolicyOptions): void

Parameters

  • policy RemovalPolicy
  • options RemovalPolicyOptions

Sets the deletion policy of the resource based on the removal policy specified.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN). In some cases, a snapshot can be taken of the resource prior to deletion (RemovalPolicy.SNAPSHOT). A list of resources that support this policy can be found in the following link:

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html#aws-attribute-deletionpolicy-options


getAtt(attributeName, typeHint?)

public getAtt(attributeName: string, typeHint?: ResolutionTypeHint): Reference

Parameters

  • attributeName string — The name of the attribute.
  • typeHint ResolutionTypeHint

Returns

  • Reference

Returns a token for an runtime attribute of this resource.

Ideally, use generated attribute accessors (e.g. resource.arn), but this can be used for future compatibility in case there is no generated attribute.


getMetadata(key)

public getMetadata(key: string): any

Parameters

  • key string

Returns

  • any

Retrieve a value value from the CloudFormation Resource Metadata.

See also: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)


inspect(inspector)

public inspect(inspector: TreeInspector): void

Parameters

  • inspector TreeInspector — - tree inspector to collect and process attributes.

Examines the CloudFormation resource and discloses attributes.


obtainDependencies()

public obtainDependencies(): Stack &#124; CfnResource[]

Returns

  • Stack | CfnResource[]

Retrieves an array of resources this resource depends on.

This assembles dependencies on resources across stacks (including nested stacks) automatically.


obtainResourceDependencies()

public obtainResourceDependencies(): CfnResource[]

Returns

  • CfnResource[]

Get a shallow copy of dependencies between this resource and other resources in the same stack.


overrideLogicalId(newLogicalId)

public overrideLogicalId(newLogicalId: string): void

Parameters

  • newLogicalId string — The new logical ID to use for this stack element.

Overrides the auto-generated logical ID with a specific ID.


removeDependency(target)

public removeDependency(target: CfnResource): void

Parameters

  • target CfnResource

Indicates that this resource no longer depends on another resource.

This can be used for resources across stacks (including nested stacks) and the dependency will automatically be removed from the relevant scope.


replaceDependency(target, newTarget)

public replaceDependency(target: CfnResource, newTarget: CfnResource): void

Parameters

  • target CfnResource — The dependency to replace.
  • newTarget CfnResource — The new dependency to add.

Replaces one dependency with another.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


protected renderProperties(props)

protected renderProperties(props: { [string]: any }): { [string]: any }

Parameters

  • props { [string]: any }

Returns

  • { [string]: any }