AWS::ECS::Cluster
The AWS::ECS::Cluster
resource creates an Amazon Elastic Container Service (Amazon ECS)
cluster.
Syntax
To declare this entity in your Amazon CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ECS::Cluster", "Properties" : { "CapacityProviders" :
[ String, ... ]
, "ClusterName" :String
, "ClusterSettings" :[ ClusterSettings, ... ]
, "Configuration" :ClusterConfiguration
, "DefaultCapacityProviderStrategy" :[ CapacityProviderStrategyItem, ... ]
, "ServiceConnectDefaults" :ServiceConnectDefaults
, "Tags" :[ Tag, ... ]
} }
YAML
Type: AWS::ECS::Cluster Properties: CapacityProviders:
- String
ClusterName:String
ClusterSettings:- ClusterSettings
Configuration:ClusterConfiguration
DefaultCapacityProviderStrategy:- CapacityProviderStrategyItem
ServiceConnectDefaults:ServiceConnectDefaults
Tags:- Tag
Properties
CapacityProviders
-
The short name of one or more capacity providers to associate with the cluster. A capacity provider must be associated with a cluster before it can be included as part of the default capacity provider strategy of the cluster or used in a capacity provider strategy when calling the CreateService or RunTask actions.
If specifying a capacity provider that uses an Auto Scaling group, the capacity provider must be created but not associated with another cluster. New Auto Scaling group capacity providers can be created with the CreateCapacityProvider API operation.
To use a Amazon Fargate capacity provider, specify either the
FARGATE
orFARGATE_SPOT
capacity providers. The Amazon Fargate capacity providers are available to all accounts and only need to be associated with a cluster to be used.The PutCapacityProvider API operation is used to update the list of available capacity providers for a cluster after the cluster is created.
Required: No
Type: List of String
Update requires: No interruption
ClusterName
-
A user-generated string that you use to identify your cluster. If you don't specify a name, Amazon CloudFormation generates a unique physical ID for the name.
Required: No
Type: String
Update requires: Replacement
ClusterSettings
-
The settings to use when creating a cluster. This parameter is used to turn on CloudWatch Container Insights for a cluster.
Required: No
Type: List of ClusterSettings
Update requires: No interruption
Configuration
-
The execute command configuration for the cluster.
Required: No
Type: ClusterConfiguration
Update requires: No interruption
DefaultCapacityProviderStrategy
-
The default capacity provider strategy for the cluster. When services or tasks are run in the cluster with no launch type or capacity provider strategy specified, the default capacity provider strategy is used.
Required: No
Type: List of CapacityProviderStrategyItem
Update requires: No interruption
ServiceConnectDefaults
-
Use this parameter to set a default Service Connect namespace. After you set a default Service Connect namespace, any new services with Service Connect turned on that are created in the cluster are added as client services in the namespace. This setting only applies to new services that set the
enabled
parameter totrue
in theServiceConnectConfiguration
. You can set the namespace of each service individually in theServiceConnectConfiguration
to override this default parameter.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.
Required: No
Type: ServiceConnectDefaults
Update requires: No interruption
Tags
-
The metadata that you apply to the cluster to help you categorize and organize them. Each tag consists of a key and an optional value. You define both.
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 Amazon 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.
Required: No
Type: List of Tag
Maximum:
50
Update requires: No interruption
-
Return values
Ref
When you pass the logical ID of this resource to the intrinsic Ref
function, Ref
returns the resource name.
In the following example, the Ref
function returns the name of the MyECSCluster
cluster, such as MyStack-MyECSCluster-NT5EUXTNTXXD
.
{ "Ref": "MyECSCluster" }
For more information about using the Ref
function, see Ref.
Fn::GetAtt
The Fn::GetAtt
intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
For more information about using the Fn::GetAtt
intrinsic function, see Fn::GetAtt.
Examples
Define a cluster with the Fargate capacity providers and a default capacity provider strategy defined
The following example defines a cluster named MyFargateCluster
with the FARGATE
and
FARGATE_SPOT
capacity providers. A default capacity provider strategy is also defined where tasks
launched will be split evenly between the FARGATE
and FARGATE_SPOT
capacity
providers.
JSON
"ECSCluster": { "Type": "AWS: : ECS: : Cluster", "Properties": { "ClusterName": "MyFargateCluster", "CapacityProviders": [ "FARGATE", "FARGATE_SPOT" ], "DefaultCapacityProviderStrategy": [ { "CapacityProvider": "FARGATE", "Weight": 1 }, { "CapacityProvider": "FARGATE_SPOT", "Weight": 1 } ] } }
YAML
ECSCluster: Type: 'AWS::ECS::Cluster' Properties: ClusterName: MyFargateCluster CapacityProviders: - FARGATE - FARGATE_SPOT DefaultCapacityProviderStrategy: - CapacityProvider: FARGATE Weight: 1 - CapacityProvider: FARGATE_SPOT Weight: 1
Define a cluster with an ECS Exec configuration defined
The following example defines a cluster named MyCluster
with ECS Exec enabled using the default
logging configuration. For more information, see Using ECS Exec for debugging in the Amazon
ECS Developer Guide.
JSON
{ "ECSCluster": { "Type": "AWS::ECS::Cluster", "Properties": { "ClusterName": "MyCluster", "Configuration": { "ExecuteCommandConfiguration": { "Logging": "DEFAULT" } } } } }
YAML
ECSCluster: Type: 'AWS::ECS::Cluster' Properties: ClusterName: MyCluster Configuration: ExecuteCommandConfiguration: Logging: DEFAULT
Define an empty cluster
The following example defines an empty cluster named MyEmptyCluster
.
JSON
"ECSCluster": { "Type": "AWS::ECS::Cluster", "Properties": { "ClusterName": "MyEmptyCluster" } }
YAML
ECSCluster: Type: 'AWS::ECS::Cluster' Properties: ClusterName: MyEmptyCluster
Define an empty cluster with CloudWatch Container Insights enabled and defined tags
The following example defines an empty cluster named MyCluster
with CloudWatch Container Insights
enabled that is tagged with the key environment
and the value production
.
JSON
"ECSCluster": { "Type": "AWS::ECS::Cluster", "Properties": { "ClusterName": "MyCluster", "ClusterSettings": [ { "Name": "containerInsights", "Value": "enabled" } ], "Tags": [ { "Key": "environment", "Value": "production" } ] } }
YAML
ECSCluster: Type: 'AWS::ECS::Cluster' Properties: ClusterName: MyCluster ClusterSettings: - Name: containerInsights Value: enabled Tags: - Key: environment Value: production