class Cluster (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ECS.Cluster |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsecs#Cluster |
![]() | software.amazon.awscdk.services.ecs.Cluster |
![]() | aws_cdk.aws_ecs.Cluster |
![]() | aws-cdk-lib » aws_ecs » Cluster |
Implements
IConstruct
, IDependable
, IResource
, ICluster
A regional grouping of one or more container instances on which you can run tasks and services.
Example
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
// The VPC and subnet must have associated IPv6 CIDR blocks.
const vpc = new ec2.Vpc(this, 'Vpc', {
ipProtocol: ec2.IpProtocol.DUAL_STACK,
});
const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc });
const service = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'myService', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
minHealthyPercent: 100,
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
});
const applicationLoadBalancedEc2Service = new ecsPatterns.ApplicationLoadBalancedEc2Service(this, 'myService', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
minHealthyPercent: 100,
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
});
Initializer
new Cluster(scope: Construct, id: string, props?: ClusterProps)
Parameters
- scope
Construct
- id
string
- props
Cluster
Props
Constructs a new instance of the Cluster class.
Construct Props
Name | Type | Description |
---|---|---|
capacity? | Add | The ec2 capacity to add to the cluster. |
cluster | string | The name for the cluster. |
container | boolean | If true CloudWatch Container Insights will be enabled for the cluster. |
container | Container | The CloudWatch Container Insights configuration for the cluster. |
default | Cloud | The service discovery namespace created in this cluster. |
enable | boolean | Whether to enable Fargate Capacity Providers. |
execute | Execute | The execute command configuration for the cluster. |
managed | Managed | Encryption configuration for ECS Managed storage. |
vpc? | IVpc | The VPC where your ECS instances will be running or your ENIs will be deployed. |
capacity?
Type:
Add
(optional, default: no EC2 capacity will be added, you can use addCapacity
to add capacity later.)
The ec2 capacity to add to the cluster.
clusterName?
Type:
string
(optional, default: CloudFormation-generated name)
The name for the cluster.
containerInsights?
⚠️ Deprecated: See {@link containerInsightsV2 }
Type:
boolean
(optional, default: Container Insights will be disabled for this cluster.)
If true CloudWatch Container Insights will be enabled for the cluster.
containerInsightsV2?
Type:
Container
(optional, default: {@link ContainerInsights.DISABLED } This may be overridden by ECS account level settings.)
The CloudWatch Container Insights configuration for the cluster.
defaultCloudMapNamespace?
Type:
Cloud
(optional, default: no service discovery namespace created, you can use addDefaultCloudMapNamespace
to add a
default service discovery namespace later.)
The service discovery namespace created in this cluster.
enableFargateCapacityProviders?
Type:
boolean
(optional, default: false)
Whether to enable Fargate Capacity Providers.
executeCommandConfiguration?
Type:
Execute
(optional, default: no configuration will be provided.)
The execute command configuration for the cluster.
managedStorageConfiguration?
Type:
Managed
(optional, default: no encryption will be applied.)
Encryption configuration for ECS Managed storage.
vpc?
Type:
IVpc
(optional, default: creates a new VPC with two AZs)
The VPC where your ECS instances will be running or your ENIs will be deployed.
Properties
Name | Type | Description |
---|---|---|
capacity | string[] | Getter for _capacityProviderNames added to cluster. |
cluster | string | The Amazon Resource Name (ARN) that identifies the cluster. |
cluster | string | The name of the cluster. |
connections | Connections | Manage the allowed network connections for the cluster with Security Groups. |
default | Capacity [] | Getter for _defaultCapacityProviderStrategy. |
env | Resource | The environment this resource belongs to. |
has | boolean | Whether the cluster has EC2 capacity associated with it. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
vpc | IVpc | The VPC associated with the cluster. |
autoscaling | IAuto | Getter for autoscaling group added to cluster. |
default | INamespace | Getter for namespace added to cluster. |
execute | Execute | Getter for execute command configuration associated with the cluster. |
capacityProviderNames
Type:
string[]
Getter for _capacityProviderNames added to cluster.
clusterArn
Type:
string
The Amazon Resource Name (ARN) that identifies the cluster.
clusterName
Type:
string
The name of the cluster.
connections
Type:
Connections
Manage the allowed network connections for the cluster with Security Groups.
defaultCapacityProviderStrategy
Type:
Capacity
[]
Getter for _defaultCapacityProviderStrategy.
This is necessary to correctly create Capacity Provider Associations.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
hasEc2Capacity
Type:
boolean
Whether the cluster has EC2 capacity associated with it.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
vpc
Type:
IVpc
The VPC associated with the cluster.
autoscalingGroup?
Type:
IAuto
(optional)
Getter for autoscaling group added to cluster.
defaultCloudMapNamespace?
Type:
INamespace
(optional)
Getter for namespace added to cluster.
executeCommandConfiguration?
Type:
Execute
(optional)
Getter for execute command configuration associated with the cluster.
Methods
Name | Description |
---|---|
add | This method adds an Auto Scaling Group Capacity Provider to a cluster. |
add | It is highly recommended to use Cluster.addAsgCapacityProvider instead of this method. |
add | Add default capacity provider strategy for this cluster. |
add | Add an AWS Cloud Map DNS namespace for this cluster. |
apply | Apply the given removal policy to this resource. |
arn | Returns an ARN that represents all tasks within the cluster that match the task pattern specified. |
enable | Enable the Fargate capacity providers for this cluster. |
grant | Grants an ECS Task Protection API permission to the specified grantee. |
metric(metricName, props?) | This method returns the specified CloudWatch metric for this cluster. |
metric | This method returns the CloudWatch metric for this clusters CPU reservation. |
metric | This method returns the CloudWatch metric for this clusters CPU utilization. |
metric | This method returns the CloudWatch metric for this clusters memory reservation. |
metric | This method returns the CloudWatch metric for this clusters memory utilization. |
to | Returns a string representation of this construct. |
static from | Import an existing cluster to the stack from the cluster ARN. |
static from | Import an existing cluster to the stack from its attributes. |
static is | Return whether the given object is a Cluster. |
addAsgCapacityProvider(provider, options?)
public addAsgCapacityProvider(provider: AsgCapacityProvider, options?: AddAutoScalingGroupCapacityOptions): void
Parameters
- provider
Asg
— the capacity provider to add to this cluster.Capacity Provider - options
Add
Auto Scaling Group Capacity Options
This method adds an Auto Scaling Group Capacity Provider to a cluster.
addCapacity(id, options)
public addCapacity(id: string, options: AddCapacityOptions): AutoScalingGroup
Parameters
- id
string
- options
Add
Capacity Options
Returns
It is highly recommended to use Cluster.addAsgCapacityProvider
instead of this method.
This method adds compute capacity to a cluster by creating an AutoScalingGroup with the specified options.
Returns the AutoScalingGroup so you can add autoscaling settings to it.
addDefaultCapacityProviderStrategy(defaultCapacityProviderStrategy)
public addDefaultCapacityProviderStrategy(defaultCapacityProviderStrategy: CapacityProviderStrategy[]): void
Parameters
- defaultCapacityProviderStrategy
Capacity
Provider Strategy []
— cluster default capacity provider strategy. This takes the form of a list of CapacityProviderStrategy objects.
Add default capacity provider strategy for this cluster.
addDefaultCloudMapNamespace(options)
public addDefaultCloudMapNamespace(options: CloudMapNamespaceOptions): INamespace
Parameters
- options
Cloud
Map Namespace Options
Returns
Add an AWS Cloud Map DNS namespace for this cluster.
NOTE: HttpNamespaces are supported only for use cases involving Service Connect. For use cases involving both Service- Discovery and Service Connect, customers should manage the HttpNamespace outside of the Cluster.addDefaultCloudMapNamespace method.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
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
).
arnForTasks(keyPattern)
public arnForTasks(keyPattern: string): string
Parameters
- keyPattern
string
— Task id pattern.
Returns
string
Returns an ARN that represents all tasks within the cluster that match the task pattern specified.
To represent all tasks, specify "*"
.
enableFargateCapacityProviders()
public enableFargateCapacityProviders(): void
Enable the Fargate capacity providers for this cluster.
grantTaskProtection(grantee)
public grantTaskProtection(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The entity (e.g., IAM role or user) to grant the permissions to.
Returns
Grants an ECS Task Protection API permission to the specified grantee.
This method provides a streamlined way to assign the 'ecs:UpdateTaskProtection' permission, enabling the grantee to manage task protection in the ECS cluster.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
This method returns the specified CloudWatch metric for this cluster.
metricCpuReservation(props?)
public metricCpuReservation(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this clusters CPU reservation.
metricCpuUtilization(props?)
public metricCpuUtilization(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this clusters CPU utilization.
metricMemoryReservation(props?)
public metricMemoryReservation(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this clusters memory reservation.
metricMemoryUtilization(props?)
public metricMemoryUtilization(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
This method returns the CloudWatch metric for this clusters memory utilization.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromClusterArn(scope, id, clusterArn)
public static fromClusterArn(scope: Construct, id: string, clusterArn: string): ICluster
Parameters
- scope
Construct
- id
string
- clusterArn
string
Returns
Import an existing cluster to the stack from the cluster ARN.
This does not provide access to the vpc, hasEc2Capacity, or connections -
use the fromClusterAttributes
method to access those properties.
static fromClusterAttributes(scope, id, attrs)
public static fromClusterAttributes(scope: Construct, id: string, attrs: ClusterAttributes): ICluster
Parameters
- scope
Construct
- id
string
- attrs
Cluster
Attributes
Returns
Import an existing cluster to the stack from its attributes.
static isCluster(x)
public static isCluster(x: any): boolean
Parameters
- x
any
Returns
boolean
Return whether the given object is a Cluster.