Class Cluster

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
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();
 
  • 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

      @Stability(Stable) public Cluster(@NotNull software.constructs.Construct scope, @NotNull String id)
      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

      @Stability(Stable) public void addAsgCapacityProvider(@NotNull AsgCapacityProvider provider)
      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.
      Use
      invalid @link
      Cluster.addAsgCapacityProvider
      instead.
      (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.
      Use
      invalid @link
      Cluster.addAsgCapacityProvider
      instead.
      (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 use
      invalid @link
      Cluster.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.
    • addCapacityProvider

      @Stability(Deprecated) @Deprecated public void addCapacityProvider(@NotNull String provider)
      Deprecated.
      (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

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName)
      This method returns the specifed CloudWatch metric for this cluster.

      Parameters:
      metricName - This parameter is required.
    • metricCpuReservation

      @Stability(Stable) @NotNull public Metric metricCpuReservation(@Nullable MetricOptions props)
      This method returns the CloudWatch metric for this clusters CPU reservation.

      Default: average over 5 minutes

      Parameters:
      props -
    • metricCpuReservation

      @Stability(Stable) @NotNull public Metric metricCpuReservation()
      This method returns the CloudWatch metric for this clusters CPU reservation.

      Default: average over 5 minutes

    • metricCpuUtilization

      @Stability(Stable) @NotNull public Metric metricCpuUtilization(@Nullable MetricOptions props)
      This method returns the CloudWatch metric for this clusters CPU utilization.

      Default: average over 5 minutes

      Parameters:
      props -
    • metricCpuUtilization

      @Stability(Stable) @NotNull public Metric metricCpuUtilization()
      This method returns the CloudWatch metric for this clusters CPU utilization.

      Default: average over 5 minutes

    • metricMemoryReservation

      @Stability(Stable) @NotNull public Metric metricMemoryReservation(@Nullable MetricOptions props)
      This method returns the CloudWatch metric for this clusters memory reservation.

      Default: average over 5 minutes

      Parameters:
      props -
    • metricMemoryReservation

      @Stability(Stable) @NotNull public Metric metricMemoryReservation()
      This method returns the CloudWatch metric for this clusters memory reservation.

      Default: average over 5 minutes

    • metricMemoryUtilization

      @Stability(Stable) @NotNull public Metric metricMemoryUtilization(@Nullable MetricOptions props)
      This method returns the CloudWatch metric for this clusters memory utilization.

      Default: average over 5 minutes

      Parameters:
      props -
    • metricMemoryUtilization

      @Stability(Stable) @NotNull public Metric metricMemoryUtilization()
      This method returns the CloudWatch metric for this clusters memory utilization.

      Default: average over 5 minutes

    • getClusterArn

      @Stability(Stable) @NotNull public String getClusterArn()
      The Amazon Resource Name (ARN) that identifies the cluster.
      Specified by:
      getClusterArn in interface ICluster
    • getClusterName

      @Stability(Stable) @NotNull public String getClusterName()
      The name of the cluster.
      Specified by:
      getClusterName in interface ICluster
    • getConnections

      @Stability(Stable) @NotNull public Connections getConnections()
      Manage the allowed network connections for the cluster with Security Groups.
      Specified by:
      getConnections in interface ICluster
    • getHasEc2Capacity

      @Stability(Stable) @NotNull public Boolean getHasEc2Capacity()
      Whether the cluster has EC2 capacity associated with it.
      Specified by:
      getHasEc2Capacity in interface ICluster
    • getVpc

      @Stability(Stable) @NotNull public IVpc getVpc()
      The VPC associated with the cluster.
      Specified by:
      getVpc in interface ICluster
    • getAutoscalingGroup

      @Stability(Stable) @Nullable public IAutoScalingGroup getAutoscalingGroup()
      Getter for autoscaling group added to cluster.
      Specified by:
      getAutoscalingGroup in interface ICluster
    • getDefaultCloudMapNamespace

      @Stability(Stable) @Nullable public INamespace getDefaultCloudMapNamespace()
      Getter for namespace added to cluster.
      Specified by:
      getDefaultCloudMapNamespace in interface ICluster
    • getExecuteCommandConfiguration

      @Stability(Stable) @Nullable public ExecuteCommandConfiguration getExecuteCommandConfiguration()
      Getter for execute command configuration associated with the cluster.
      Specified by:
      getExecuteCommandConfiguration in interface ICluster