Class Cluster
- All Implemented Interfaces:
IResource
,ICluster
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
Example:
IVpc vpc = Vpc.fromLookup(this, "Vpc", VpcLookupOptions.builder() .isDefault(true) .build()); Cluster cluster = Cluster.Builder.create(this, "ECSCluster").vpc(vpc).build(); TaskDefinition taskDefinition = TaskDefinition.Builder.create(this, "TD") .compatibility(Compatibility.FARGATE) .cpu("256") .memoryMiB("512") .build(); taskDefinition.addContainer("TheContainer", ContainerDefinitionOptions.builder() .image(ContainerImage.fromRegistry("foo/bar")) .build()); EcsRunTask runTask = EcsRunTask.Builder.create(this, "Run") .integrationPattern(IntegrationPattern.RUN_JOB) .cluster(cluster) .taskDefinition(taskDefinition) .launchTarget(new EcsFargateLaunchTarget()) .cpu("1024") .memoryMiB("1048") .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.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.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.addCapacity
(String id, AddCapacityOptions options) It is highly recommended to useCluster.addAsgCapacityProvider
instead of this method.void
addDefaultCapacityProviderStrategy
(List<CapacityProviderStrategy> defaultCapacityProviderStrategy) Add default capacity provider strategy for this cluster.Add an AWS Cloud Map DNS namespace for this cluster.arnForTasks
(String keyPattern) Returns an ARN that represents all tasks within the cluster that match the task pattern specified.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.Getter for _capacityProviderNames 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 _defaultCapacityProviderStrategy.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.grantTaskProtection
(IGrantable grantee) Grants an ECS Task Protection API permission to the specified grantee.static Boolean
Return whether the given object is a 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.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, 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.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.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.
-
isCluster
Return whether the given object is a Cluster.- Parameters:
x
- 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.
-
addCapacity
@Stability(Stable) @NotNull public AutoScalingGroup addCapacity(@NotNull String id, @NotNull AddCapacityOptions options) It is highly recommended to useCluster.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.
- Parameters:
id
- This parameter is required.options
- This parameter is required.
-
addDefaultCapacityProviderStrategy
@Stability(Stable) public void addDefaultCapacityProviderStrategy(@NotNull List<CapacityProviderStrategy> defaultCapacityProviderStrategy) Add default capacity provider strategy for this cluster.- Parameters:
defaultCapacityProviderStrategy
- cluster default capacity provider strategy. This takes the form of a list of CapacityProviderStrategy objects. This parameter is required.
-
addDefaultCloudMapNamespace
@Stability(Stable) @NotNull public INamespace addDefaultCloudMapNamespace(@NotNull CloudMapNamespaceOptions options) 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.
- Parameters:
options
- This parameter is required.
-
arnForTasks
Returns an ARN that represents all tasks within the cluster that match the task pattern specified.To represent all tasks, specify
"*"
.- Parameters:
keyPattern
- Task id pattern. This parameter is required.
-
enableFargateCapacityProviders
@Stability(Stable) public void enableFargateCapacityProviders()Enable the Fargate capacity providers for this cluster. -
grantTaskProtection
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.
- Parameters:
grantee
- The entity (e.g., IAM role or user) to grant the permissions to. This parameter is required.
-
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
-
getCapacityProviderNames
Getter for _capacityProviderNames added to cluster. -
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
-
getDefaultCapacityProviderStrategy
@Stability(Stable) @NotNull public List<CapacityProviderStrategy> getDefaultCapacityProviderStrategy()Getter for _defaultCapacityProviderStrategy.This is necessary to correctly create Capacity Provider Associations.
-
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
-