Show / Hide Table of Contents

Class Cluster

A regional grouping of one or more container instances on which you can run tasks and services.

Inheritance
object
Resource
Cluster
Implements
ICluster
IResource
IConstruct
IDependable
IEnvironmentAware
Inherited Members
Resource.IsOwnedResource(IConstruct)
Resource.IsResource(IConstruct)
Resource.ApplyRemovalPolicy(RemovalPolicy)
Resource.GeneratePhysicalName()
Resource.GetResourceArnAttribute(string, IArnComponents)
Resource.GetResourceNameAttribute(string)
Resource.Env
Resource.PhysicalName
Resource.Stack
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Cluster : Resource, ICluster, IResource, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class Cluster Inherits Resource Implements ICluster, IResource, IConstruct, IDependable, IEnvironmentAware
Remarks

ExampleMetadata: infused

Examples
Vpc vpc;


            var cluster = new Cluster(this, "Cluster", new ClusterProps {
                Vpc = vpc
            });

            var autoScalingGroup = new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
                Vpc = vpc,
                InstanceType = new InstanceType("t2.micro"),
                MachineImage = EcsOptimizedImage.AmazonLinux2(),
                MinCapacity = 0,
                MaxCapacity = 100
            });

            var capacityProvider = new AsgCapacityProvider(this, "AsgCapacityProvider", new AsgCapacityProviderProps {
                AutoScalingGroup = autoScalingGroup,
                InstanceWarmupPeriod = 300
            });
            cluster.AddAsgCapacityProvider(capacityProvider);

            var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");

            taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
                Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
                MemoryReservationMiB = 256
            });

            new Ec2Service(this, "EC2Service", new Ec2ServiceProps {
                Cluster = cluster,
                TaskDefinition = taskDefinition,
                MinHealthyPercent = 100,
                CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
                    CapacityProvider = capacityProvider.CapacityProviderName,
                    Weight = 1
                } }
            });

Synopsis

Constructors

Cluster(Construct, string, IClusterProps?)

Constructs a new instance of the Cluster class.

Properties

AutoscalingGroup

Getter for autoscaling group added to cluster.

CapacityProviderNames

Getter for _capacityProviderNames added to cluster.

ClusterArn

The Amazon Resource Name (ARN) that identifies the cluster.

ClusterName

The name of the cluster.

ClusterScopedCapacityProviderNames

Getter for _clusterScopedCapacityProviderNames.

Connections

Manage the allowed network connections for the cluster with Security Groups.

DefaultCapacityProviderStrategy

Getter for _defaultCapacityProviderStrategy.

DefaultCloudMapNamespace

Getter for namespace added to cluster.

ExecuteCommandConfiguration

Getter for execute command configuration associated with the cluster.

HasEc2Capacity

Whether the cluster has EC2 capacity associated with it.

PROPERTY_INJECTION_ID

Uniquely identifies this class.

Vpc

The VPC associated with the cluster.

Methods

AddAsgCapacityProvider(AsgCapacityProvider, IAddAutoScalingGroupCapacityOptions?)

This method adds an Auto Scaling Group Capacity Provider to a cluster.

AddCapacity(string, IAddCapacityOptions)

It is highly recommended to use Cluster.addAsgCapacityProvider instead of this method.

AddDefaultCapacityProviderStrategy(ICapacityProviderStrategy[])

Add default capacity provider strategy for this cluster.

AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions)

Add an AWS Cloud Map DNS namespace for this cluster.

AddManagedInstancesCapacityProvider(ManagedInstancesCapacityProvider)

This method adds a Managed Instances Capacity Provider to a cluster.

ArnForTasks(string)

Returns an ARN that represents all tasks within the cluster that match the task pattern specified.

EnableFargateCapacityProviders()

Enable the Fargate capacity providers for this cluster.

FromClusterArn(Construct, string, string)

Import an existing cluster to the stack from the cluster ARN.

FromClusterAttributes(Construct, string, IClusterAttributes)

Import an existing cluster to the stack from its attributes.

GrantTaskProtection(IGrantable)

Grants an ECS Task Protection API permission to the specified grantee.

IsCluster(object)

Return whether the given object is a Cluster.

Metric(string, IMetricOptions?)

This method returns the specified CloudWatch metric for this cluster.

MetricCpuReservation(IMetricOptions?)

This method returns the CloudWatch metric for this clusters CPU reservation.

MetricCpuUtilization(IMetricOptions?)

This method returns the CloudWatch metric for this clusters CPU utilization.

MetricMemoryReservation(IMetricOptions?)

This method returns the CloudWatch metric for this clusters memory reservation.

MetricMemoryUtilization(IMetricOptions?)

This method returns the CloudWatch metric for this clusters memory utilization.

Constructors

Cluster(Construct, string, IClusterProps?)

Constructs a new instance of the Cluster class.

public Cluster(Construct scope, string id, IClusterProps? props = null)
Parameters
scope Construct
id string
props IClusterProps
Remarks

ExampleMetadata: infused

Properties

AutoscalingGroup

Getter for autoscaling group added to cluster.

public virtual IAutoScalingGroup? AutoscalingGroup { get; }
Property Value

IAutoScalingGroup

Remarks

ExampleMetadata: infused

CapacityProviderNames

Getter for _capacityProviderNames added to cluster.

public virtual string[] CapacityProviderNames { get; }
Property Value

string[]

Remarks

ExampleMetadata: infused

ClusterArn

The Amazon Resource Name (ARN) that identifies the cluster.

public virtual string ClusterArn { get; }
Property Value

string

Remarks

ExampleMetadata: infused

ClusterName

The name of the cluster.

public virtual string ClusterName { get; }
Property Value

string

Remarks

ExampleMetadata: infused

ClusterScopedCapacityProviderNames

Getter for _clusterScopedCapacityProviderNames.

public virtual string[] ClusterScopedCapacityProviderNames { get; }
Property Value

string[]

Remarks

Attribute: true

Connections

Manage the allowed network connections for the cluster with Security Groups.

public virtual Connections_ Connections { get; }
Property Value

Connections_

Remarks

ExampleMetadata: infused

DefaultCapacityProviderStrategy

Getter for _defaultCapacityProviderStrategy.

public virtual ICapacityProviderStrategy[] DefaultCapacityProviderStrategy { get; }
Property Value

ICapacityProviderStrategy[]

Remarks

This is necessary to correctly create Capacity Provider Associations.

DefaultCloudMapNamespace

Getter for namespace added to cluster.

public virtual INamespace? DefaultCloudMapNamespace { get; }
Property Value

INamespace

Remarks

ExampleMetadata: infused

ExecuteCommandConfiguration

Getter for execute command configuration associated with the cluster.

public virtual IExecuteCommandConfiguration? ExecuteCommandConfiguration { get; }
Property Value

IExecuteCommandConfiguration

Remarks

ExampleMetadata: infused

HasEc2Capacity

Whether the cluster has EC2 capacity associated with it.

public virtual bool HasEc2Capacity { get; }
Property Value

bool

Remarks

ExampleMetadata: infused

PROPERTY_INJECTION_ID

Uniquely identifies this class.

public static string PROPERTY_INJECTION_ID { get; }
Property Value

string

Remarks

ExampleMetadata: infused

Vpc

The VPC associated with the cluster.

public virtual IVpc Vpc { get; }
Property Value

IVpc

Remarks

ExampleMetadata: infused

Methods

AddAsgCapacityProvider(AsgCapacityProvider, IAddAutoScalingGroupCapacityOptions?)

This method adds an Auto Scaling Group Capacity Provider to a cluster.

public virtual void AddAsgCapacityProvider(AsgCapacityProvider provider, IAddAutoScalingGroupCapacityOptions? options = null)
Parameters
provider AsgCapacityProvider

the capacity provider to add to this cluster.

options IAddAutoScalingGroupCapacityOptions

the capacity provider to add to this cluster.

Remarks

ExampleMetadata: infused

AddCapacity(string, IAddCapacityOptions)

It is highly recommended to use Cluster.addAsgCapacityProvider instead of this method.

public virtual AutoScalingGroup AddCapacity(string id, IAddCapacityOptions options)
Parameters
id string
options IAddCapacityOptions
Returns

AutoScalingGroup

Remarks

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(ICapacityProviderStrategy[])

Add default capacity provider strategy for this cluster.

public virtual void AddDefaultCapacityProviderStrategy(ICapacityProviderStrategy[] defaultCapacityProviderStrategy)
Parameters
defaultCapacityProviderStrategy ICapacityProviderStrategy[]

cluster default capacity provider strategy. This takes the form of a list of CapacityProviderStrategy objects.

Remarks

ExampleMetadata: infused

AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions)

Add an AWS Cloud Map DNS namespace for this cluster.

public virtual INamespace AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions options)
Parameters
options ICloudMapNamespaceOptions
Returns

INamespace

Remarks

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.

AddManagedInstancesCapacityProvider(ManagedInstancesCapacityProvider)

This method adds a Managed Instances Capacity Provider to a cluster.

public virtual void AddManagedInstancesCapacityProvider(ManagedInstancesCapacityProvider provider)
Parameters
provider ManagedInstancesCapacityProvider

the capacity provider to add to this cluster.

Remarks

ExampleMetadata: infused

ArnForTasks(string)

Returns an ARN that represents all tasks within the cluster that match the task pattern specified.

public virtual string ArnForTasks(string keyPattern)
Parameters
keyPattern string

Task id pattern.

Returns

string

Remarks

To represent all tasks, specify "*".

EnableFargateCapacityProviders()

Enable the Fargate capacity providers for this cluster.

public virtual void EnableFargateCapacityProviders()
Remarks

ExampleMetadata: infused

FromClusterArn(Construct, string, string)

Import an existing cluster to the stack from the cluster ARN.

public static ICluster FromClusterArn(Construct scope, string id, string clusterArn)
Parameters
scope Construct
id string
clusterArn string
Returns

ICluster

Remarks

This does not provide access to the vpc, hasEc2Capacity, or connections - use the fromClusterAttributes method to access those properties.

FromClusterAttributes(Construct, string, IClusterAttributes)

Import an existing cluster to the stack from its attributes.

public static ICluster FromClusterAttributes(Construct scope, string id, IClusterAttributes attrs)
Parameters
scope Construct
id string
attrs IClusterAttributes
Returns

ICluster

Remarks

ExampleMetadata: infused

GrantTaskProtection(IGrantable)

Grants an ECS Task Protection API permission to the specified grantee.

public virtual Grant GrantTaskProtection(IGrantable grantee)
Parameters
grantee IGrantable

The entity (e.g., IAM role or user) to grant the permissions to.

Returns

Grant

Remarks

This method provides a streamlined way to assign the 'ecs:UpdateTaskProtection' permission, enabling the grantee to manage task protection in the ECS cluster.

IsCluster(object)

Return whether the given object is a Cluster.

public static bool IsCluster(object x)
Parameters
x object
Returns

bool

Remarks

ExampleMetadata: infused

Metric(string, IMetricOptions?)

This method returns the specified CloudWatch metric for this cluster.

public virtual Metric Metric(string metricName, IMetricOptions? props = null)
Parameters
metricName string
props IMetricOptions
Returns

Metric

Remarks

ExampleMetadata: infused

MetricCpuReservation(IMetricOptions?)

This method returns the CloudWatch metric for this clusters CPU reservation.

public virtual Metric MetricCpuReservation(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: average over 5 minutes

MetricCpuUtilization(IMetricOptions?)

This method returns the CloudWatch metric for this clusters CPU utilization.

public virtual Metric MetricCpuUtilization(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: average over 5 minutes

MetricMemoryReservation(IMetricOptions?)

This method returns the CloudWatch metric for this clusters memory reservation.

public virtual Metric MetricMemoryReservation(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: average over 5 minutes

MetricMemoryUtilization(IMetricOptions?)

This method returns the CloudWatch metric for this clusters memory utilization.

public virtual Metric MetricMemoryUtilization(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: average over 5 minutes

Implements

ICluster
IResource
Constructs.IConstruct
Constructs.IDependable
IEnvironmentAware
Back to top Generated by DocFX