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.AWS.ECS.dll
Syntax (csharp)
public class Cluster : Resource, ICluster, IResource, IConstruct, IDependable
Syntax (vb)
Public Class Cluster
Inherits Resource
Implements ICluster, IResource, IConstruct, IDependable
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
});
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,
CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
CapacityProvider = capacityProvider.CapacityProviderName,
Weight = 1
} }
});
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. |
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. |
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. |
AddAutoScalingGroup(AutoScalingGroup, IAddAutoScalingGroupCapacityOptions) | (deprecated) This method adds compute capacity to a cluster using the specified AutoScalingGroup. |
AddCapacity(String, IAddCapacityOptions) | It is highly recommended to use {@link Cluster.addAsgCapacityProvider} instead of this method. |
AddCapacityProvider(String) | (deprecated) This method enables the Fargate or Fargate Spot capacity providers on the cluster. |
AddDefaultCloudMapNamespace(ICloudMapNamespaceOptions) | Add an AWS Cloud Map DNS namespace for this cluster. |
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. |
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
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
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.
AddAutoScalingGroup(AutoScalingGroup, IAddAutoScalingGroupCapacityOptions)
(deprecated) This method adds compute capacity to a cluster using the specified AutoScalingGroup.
public virtual void AddAutoScalingGroup(AutoScalingGroup autoScalingGroup, IAddAutoScalingGroupCapacityOptions options = null)
Parameters
- autoScalingGroup AutoScalingGroup
the ASG to add to this cluster.
- options IAddAutoScalingGroupCapacityOptions
the ASG to add to this cluster.
Remarks
Stability: Deprecated
AddCapacity(String, IAddCapacityOptions)
It is highly recommended to use {@link 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.
AddCapacityProvider(String)
(deprecated) This method enables the Fargate or Fargate Spot capacity providers on the cluster.
public virtual void AddCapacityProvider(string provider)
Parameters
- provider System.String
the capacity provider to add to this cluster.
Remarks
Stability: Deprecated
See: {@link addAsgCapacityProvider} to add an Auto Scaling Group capacity provider to the cluster.
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 not supported, as ECS always requires a DNSConfig when registering an instance to a Cloud Map service.
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
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