Class Cluster
A regional grouping of one or more container instances on which you can run tasks and services.
Inherited Members
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Cluster : Resource, ICluster, IResource
Syntax (vb)
Public Class Cluster
Inherits Resource
Implements ICluster, IResource
Remarks
ExampleMetadata: infused
Examples
using Amazon.CDK;
var vpc = new Vpc(this, "Vpc", new VpcProps { MaxAzs = 1 });
var cluster = new Cluster(this, "EcsCluster", new ClusterProps { Vpc = vpc });
var taskDefinition = new FargateTaskDefinition(this, "TaskDef", new FargateTaskDefinitionProps {
MemoryLimitMiB = 512,
Cpu = 256
});
taskDefinition.AddContainer("WebContainer", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample")
});
Tags.Of(taskDefinition).Add("my-tag", "my-tag-value");
var scheduledFargateTask = new ScheduledFargateTask(this, "ScheduledFargateTask", new ScheduledFargateTaskProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
Schedule = Schedule.Expression("rate(1 minute)"),
PropagateTags = PropagatedTagSource.TASK_DEFINITION
});
Synopsis
Constructors
Cluster(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Cluster(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
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. |
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. |
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 |
AddDefaultCapacityProviderStrategy(ICapacityProviderStrategy[]) | Add default capacity provider strategy for this cluster. |
AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions) | Add an AWS Cloud Map DNS namespace for this 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 specifed 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(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Cluster(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Cluster(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Cluster(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Cluster(Construct, String, IClusterProps)
Constructs a new instance of the Cluster class.
public Cluster(Construct scope, string id, IClusterProps props = null)
Parameters
- scope Constructs.Construct
- id System.String
- props IClusterProps
Properties
AutoscalingGroup
Getter for autoscaling group added to cluster.
public virtual IAutoScalingGroup AutoscalingGroup { get; }
Property Value
CapacityProviderNames
Getter for _capacityProviderNames added to cluster.
public virtual string[] CapacityProviderNames { get; }
Property Value
System.String[]
ClusterArn
The Amazon Resource Name (ARN) that identifies the cluster.
public virtual string ClusterArn { get; }
Property Value
System.String
ClusterName
The name of the cluster.
public virtual string ClusterName { get; }
Property Value
System.String
Connections
Manage the allowed network connections for the cluster with Security Groups.
public virtual Connections_ Connections { get; }
Property Value
DefaultCapacityProviderStrategy
Getter for _defaultCapacityProviderStrategy.
public virtual ICapacityProviderStrategy[] DefaultCapacityProviderStrategy { get; }
Property Value
Remarks
This is necessary to correctly create Capacity Provider Associations.
DefaultCloudMapNamespace
Getter for namespace added to cluster.
public virtual INamespace DefaultCloudMapNamespace { get; }
Property Value
ExecuteCommandConfiguration
Getter for execute command configuration associated with the cluster.
public virtual IExecuteCommandConfiguration ExecuteCommandConfiguration { get; }
Property Value
HasEc2Capacity
Whether the cluster has EC2 capacity associated with it.
public virtual bool HasEc2Capacity { get; }
Property Value
System.Boolean
Vpc
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.
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 System.String
- options IAddCapacityOptions
Returns
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.
AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions)
Add an AWS Cloud Map DNS namespace for this cluster.
public virtual INamespace AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions options)
Parameters
- options ICloudMapNamespaceOptions
Returns
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.
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 System.String
Task id pattern.
Returns
System.String
Remarks
To represent all tasks, specify "*"
.
EnableFargateCapacityProviders()
Enable the Fargate capacity providers for this cluster.
public virtual void EnableFargateCapacityProviders()
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 Constructs.Construct
- id System.String
- clusterArn System.String
Returns
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 Constructs.Construct
- id System.String
- attrs IClusterAttributes
Returns
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
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 System.Object
Returns
System.Boolean
Metric(String, IMetricOptions)
This method returns the specifed CloudWatch metric for this cluster.
public virtual Metric Metric(string metricName, IMetricOptions props = null)
Parameters
- metricName System.String
- props IMetricOptions
Returns
MetricCpuReservation(IMetricOptions)
This method returns the CloudWatch metric for this clusters CPU reservation.
public virtual Metric MetricCpuReservation(IMetricOptions props = null)
Parameters
- props IMetricOptions
Returns
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
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
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
Remarks
Default: average over 5 minutes