Class Cluster
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.Resource
software.amazon.awscdk.services.ecs.Cluster
- All Implemented Interfaces:
IConstruct
,IDependable
,IResource
,ICluster
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)",
date="2023-06-19T16:30:47.242Z")
@Stability(Stable)
public class Cluster
extends Resource
implements ICluster
A regional grouping of one or more container instances on which you can run tasks and services.
Example:
Vpc vpc; Cluster cluster = Cluster.Builder.create(this, "Cluster") .vpc(vpc) .build(); AutoScalingGroup autoScalingGroup = AutoScalingGroup.Builder.create(this, "ASG") .vpc(vpc) .instanceType(new InstanceType("t2.micro")) .machineImage(EcsOptimizedImage.amazonLinux2()) .minCapacity(0) .maxCapacity(100) .build(); AsgCapacityProvider capacityProvider = AsgCapacityProvider.Builder.create(this, "AsgCapacityProvider") .autoScalingGroup(autoScalingGroup) .build(); cluster.addAsgCapacityProvider(capacityProvider); Ec2TaskDefinition taskDefinition = new Ec2TaskDefinition(this, "TaskDef"); taskDefinition.addContainer("web", ContainerDefinitionOptions.builder() .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample")) .memoryReservationMiB(256) .build()); Ec2Service.Builder.create(this, "EC2Service") .cluster(cluster) .taskDefinition(taskDefinition) .capacityProviderStrategies(List.of(CapacityProviderStrategy.builder() .capacityProvider(capacityProvider.getCapacityProviderName()) .weight(1) .build())) .build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.ICluster
ICluster.Jsii$Default, ICluster.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IResource
IResource.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionprotected
Cluster
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
Cluster
(software.amazon.jsii.JsiiObjectRef objRef) Constructs a new instance of the Cluster class.Cluster
(software.constructs.Construct scope, String id, ClusterProps props) Constructs a new instance of the Cluster class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAsgCapacityProvider
(AsgCapacityProvider provider) This method adds an Auto Scaling Group Capacity Provider to a cluster.void
addAsgCapacityProvider
(AsgCapacityProvider provider, AddAutoScalingGroupCapacityOptions options) This method adds an Auto Scaling Group Capacity Provider to a cluster.void
addAutoScalingGroup
(AutoScalingGroup autoScalingGroup) Deprecated.void
addAutoScalingGroup
(AutoScalingGroup autoScalingGroup, AddAutoScalingGroupCapacityOptions options) Deprecated.Useinvalid @link
Cluster.addAsgCapacityProvider
addCapacity
(String id, AddCapacityOptions options) It is highly recommended to useinvalid @link
Cluster.addAsgCapacityProvider
void
addCapacityProvider
(String provider) Deprecated.UseenableFargateCapacityProviders()
instead.Add an AWS Cloud Map DNS namespace for this cluster.void
Enable the Fargate capacity providers for this cluster.static ICluster
fromClusterArn
(software.constructs.Construct scope, String id, String clusterArn) Import an existing cluster to the stack from the cluster ARN.static ICluster
fromClusterAttributes
(software.constructs.Construct scope, String id, ClusterAttributes attrs) Import an existing cluster to the stack from its attributes.Getter for autoscaling group added to cluster.The Amazon Resource Name (ARN) that identifies the cluster.The name of the cluster.Manage the allowed network connections for the cluster with Security Groups.Getter for namespace added to cluster.Getter for execute command configuration associated with the cluster.Whether the cluster has EC2 capacity associated with it.getVpc()
The VPC associated with the cluster.This method returns the specifed CloudWatch metric for this cluster.metric
(String metricName, MetricOptions props) This method returns the specifed CloudWatch metric for this cluster.This method returns the CloudWatch metric for this clusters CPU reservation.This method returns the CloudWatch metric for this clusters CPU reservation.This method returns the CloudWatch metric for this clusters CPU utilization.This method returns the CloudWatch metric for this clusters CPU utilization.This method returns the CloudWatch metric for this clusters memory reservation.This method returns the CloudWatch metric for this clusters memory reservation.This method returns the CloudWatch metric for this clusters memory utilization.This method returns the CloudWatch metric for this clusters memory utilization.Methods inherited from class software.amazon.awscdk.core.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResource
Methods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
Methods inherited from class software.constructs.Construct
toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.awscdk.core.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.core.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Cluster
protected Cluster(software.amazon.jsii.JsiiObjectRef objRef) -
Cluster
protected Cluster(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Cluster
@Stability(Stable) public Cluster(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable ClusterProps props) Constructs a new instance of the Cluster class.- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
-
-
Cluster
Constructs a new instance of the Cluster class.- Parameters:
scope
- This parameter is required.id
- This parameter is required.
-
-
Method Details
-
fromClusterArn
@Stability(Stable) @NotNull public static ICluster fromClusterArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String clusterArn) 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.- Parameters:
scope
- This parameter is required.id
- This parameter is required.clusterArn
- This parameter is required.
-
fromClusterAttributes
@Stability(Stable) @NotNull public static ICluster fromClusterAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull ClusterAttributes attrs) Import an existing cluster to the stack from its attributes.- Parameters:
scope
- This parameter is required.id
- This parameter is required.attrs
- This parameter is required.
-
addAsgCapacityProvider
@Stability(Stable) public void addAsgCapacityProvider(@NotNull AsgCapacityProvider provider, @Nullable AddAutoScalingGroupCapacityOptions options) This method adds an Auto Scaling Group Capacity Provider to a cluster.- Parameters:
provider
- the capacity provider to add to this cluster. This parameter is required.options
-
-
addAsgCapacityProvider
This method adds an Auto Scaling Group Capacity Provider to a cluster.- Parameters:
provider
- the capacity provider to add to this cluster. This parameter is required.
-
addAutoScalingGroup
@Stability(Deprecated) @Deprecated public void addAutoScalingGroup(@NotNull AutoScalingGroup autoScalingGroup, @Nullable AddAutoScalingGroupCapacityOptions options) Deprecated.Useinvalid @link
Cluster.addAsgCapacityProvider
(deprecated) This method adds compute capacity to a cluster using the specified AutoScalingGroup.- Parameters:
autoScalingGroup
- the ASG to add to this cluster. This parameter is required.options
-
-
addAutoScalingGroup
@Stability(Deprecated) @Deprecated public void addAutoScalingGroup(@NotNull AutoScalingGroup autoScalingGroup) Deprecated.Useinvalid @link
Cluster.addAsgCapacityProvider
(deprecated) This method adds compute capacity to a cluster using the specified AutoScalingGroup.- Parameters:
autoScalingGroup
- the ASG to add to this cluster. This parameter is required.
-
addCapacity
@Stability(Stable) @NotNull public AutoScalingGroup addCapacity(@NotNull String id, @NotNull AddCapacityOptions options) It is highly recommended to useinvalid @link
Cluster.addAsgCapacityProvider
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.
- Parameters:
id
- This parameter is required.options
- This parameter is required.
-
addCapacityProvider
Deprecated.UseenableFargateCapacityProviders()
instead.(deprecated) This method enables the Fargate or Fargate Spot capacity providers on the cluster.- Parameters:
provider
- the capacity provider to add to this cluster. This parameter is required.- See Also:
-
addDefaultCloudMapNamespace
@Stability(Stable) @NotNull public INamespace addDefaultCloudMapNamespace(@NotNull CloudMapNamespaceOptions options) Add an AWS Cloud Map DNS namespace for this cluster.NOTE: HttpNamespaces are not supported, as ECS always requires a DNSConfig when registering an instance to a Cloud Map service.
- Parameters:
options
- This parameter is required.
-
enableFargateCapacityProviders
@Stability(Stable) public void enableFargateCapacityProviders()Enable the Fargate capacity providers for this cluster. -
metric
@Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props) This method returns the specifed CloudWatch metric for this cluster.- Parameters:
metricName
- This parameter is required.props
-
-
metric
This method returns the specifed CloudWatch metric for this cluster.- Parameters:
metricName
- This parameter is required.
-
metricCpuReservation
This method returns the CloudWatch metric for this clusters CPU reservation.Default: average over 5 minutes
- Parameters:
props
-
-
metricCpuReservation
This method returns the CloudWatch metric for this clusters CPU reservation.Default: average over 5 minutes
-
metricCpuUtilization
This method returns the CloudWatch metric for this clusters CPU utilization.Default: average over 5 minutes
- Parameters:
props
-
-
metricCpuUtilization
This method returns the CloudWatch metric for this clusters CPU utilization.Default: average over 5 minutes
-
metricMemoryReservation
This method returns the CloudWatch metric for this clusters memory reservation.Default: average over 5 minutes
- Parameters:
props
-
-
metricMemoryReservation
This method returns the CloudWatch metric for this clusters memory reservation.Default: average over 5 minutes
-
metricMemoryUtilization
This method returns the CloudWatch metric for this clusters memory utilization.Default: average over 5 minutes
- Parameters:
props
-
-
metricMemoryUtilization
This method returns the CloudWatch metric for this clusters memory utilization.Default: average over 5 minutes
-
getClusterArn
The Amazon Resource Name (ARN) that identifies the cluster.- Specified by:
getClusterArn
in interfaceICluster
-
getClusterName
The name of the cluster.- Specified by:
getClusterName
in interfaceICluster
-
getConnections
Manage the allowed network connections for the cluster with Security Groups.- Specified by:
getConnections
in interfaceICluster
-
getHasEc2Capacity
Whether the cluster has EC2 capacity associated with it.- Specified by:
getHasEc2Capacity
in interfaceICluster
-
getVpc
The VPC associated with the cluster. -
getAutoscalingGroup
Getter for autoscaling group added to cluster.- Specified by:
getAutoscalingGroup
in interfaceICluster
-
getDefaultCloudMapNamespace
Getter for namespace added to cluster.- Specified by:
getDefaultCloudMapNamespace
in interfaceICluster
-
getExecuteCommandConfiguration
Getter for execute command configuration associated with the cluster.- Specified by:
getExecuteCommandConfiguration
in interfaceICluster
-
invalid @link