Class Cluster
- All Implemented Interfaces:
IEnvironmentAware,IResource,ICluster,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
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)
.instanceWarmupPeriod(300)
.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)
.minHealthyPercent(100)
.capacityProviderStrategies(List.of(CapacityProviderStrategy.builder()
.capacityProvider(capacityProvider.getCapacityProviderName())
.weight(1)
.build()))
.build();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.ICluster
ICluster.Jsii$Default, ICluster.Jsii$ProxyNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCluster(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedCluster(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 TypeMethodDescriptionvoidaddAsgCapacityProvider(AsgCapacityProvider provider) This method adds an Auto Scaling Group Capacity Provider to a cluster.voidaddAsgCapacityProvider(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.addAsgCapacityProviderinstead of this method.voidaddDefaultCapacityProviderStrategy(List<CapacityProviderStrategy> defaultCapacityProviderStrategy) Add default capacity provider strategy for this cluster.Add an AWS Cloud Map DNS namespace for this cluster.voidThis method adds a Managed Instances Capacity Provider to a cluster.arnForTasks(String keyPattern) Returns an ARN that represents all tasks within the cluster that match the task pattern specified.voidEnable the Fargate capacity providers for this cluster.static IClusterfromClusterArn(software.constructs.Construct scope, String id, String clusterArn) Import an existing cluster to the stack from the cluster ARN.static IClusterfromClusterAttributes(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.Getter for _clusterScopedCapacityProviderNames.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 BooleanReturn whether the given object is a Cluster.This method returns the specified CloudWatch metric for this cluster.metric(String metricName, MetricOptions props) This method returns the specified 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, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.IEnvironmentAware
getEnvMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
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
fromClusterAttributesmethod 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.addAsgCapacityProviderinstead 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.
-
addManagedInstancesCapacityProvider
@Stability(Stable) public void addManagedInstancesCapacityProvider(@NotNull ManagedInstancesCapacityProvider provider) This method adds a Managed Instances Capacity Provider to a cluster.- Parameters:
provider- the capacity provider to add to this cluster. 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 specified CloudWatch metric for this cluster.- Parameters:
metricName- This parameter is required.props-
-
metric
This method returns the specified 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:
getClusterArnin interfaceICluster
-
getClusterName
The name of the cluster.- Specified by:
getClusterNamein interfaceICluster
-
getClusterScopedCapacityProviderNames
Getter for _clusterScopedCapacityProviderNames. -
getConnections
Manage the allowed network connections for the cluster with Security Groups.- Specified by:
getConnectionsin 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:
getHasEc2Capacityin interfaceICluster
-
getVpc
The VPC associated with the cluster. -
getAutoscalingGroup
Getter for autoscaling group added to cluster.- Specified by:
getAutoscalingGroupin interfaceICluster
-
getDefaultCloudMapNamespace
Getter for namespace added to cluster.- Specified by:
getDefaultCloudMapNamespacein interfaceICluster
-
getExecuteCommandConfiguration
Getter for execute command configuration associated with the cluster.- Specified by:
getExecuteCommandConfigurationin interfaceICluster
-