ClusterProps

class aws_cdk.aws_ecs.ClusterProps(*, capacity=None, cluster_name=None, container_insights=None, default_cloud_map_namespace=None, enable_fargate_capacity_providers=None, execute_command_configuration=None, vpc=None)

Bases: object

The properties used to define an ECS cluster.

Parameters:
  • capacity (Union[AddCapacityOptions, Dict[str, Any], None]) – The ec2 capacity to add to the cluster. Default: - no EC2 capacity will be added, you can use addCapacity to add capacity later.

  • cluster_name (Optional[str]) – The name for the cluster. Default: CloudFormation-generated name

  • container_insights (Optional[bool]) – If true CloudWatch Container Insights will be enabled for the cluster. Default: - Container Insights will be disabled for this cluster.

  • default_cloud_map_namespace (Union[CloudMapNamespaceOptions, Dict[str, Any], None]) – The service discovery namespace created in this cluster. Default: - no service discovery namespace created, you can use addDefaultCloudMapNamespace to add a default service discovery namespace later.

  • enable_fargate_capacity_providers (Optional[bool]) – Whether to enable Fargate Capacity Providers. Default: false

  • execute_command_configuration (Union[ExecuteCommandConfiguration, Dict[str, Any], None]) – The execute command configuration for the cluster. Default: - no configuration will be provided.

  • vpc (Optional[IVpc]) – The VPC where your ECS instances will be running or your ENIs will be deployed. Default: - creates a new VPC with two AZs

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc


cluster = ecs.Cluster(self, "Cluster",
    vpc=vpc
)

auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    instance_type=ec2.InstanceType("t2.micro"),
    machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
    min_capacity=0,
    max_capacity=100
)

capacity_provider = ecs.AsgCapacityProvider(self, "AsgCapacityProvider",
    auto_scaling_group=auto_scaling_group,
    instance_warmup_period=300
)
cluster.add_asg_capacity_provider(capacity_provider)

task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")

task_definition.add_container("web",
    image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
    memory_reservation_mi_b=256
)

ecs.Ec2Service(self, "EC2Service",
    cluster=cluster,
    task_definition=task_definition,
    capacity_provider_strategies=[ecs.CapacityProviderStrategy(
        capacity_provider=capacity_provider.capacity_provider_name,
        weight=1
    )
    ]
)

Attributes

capacity

The ec2 capacity to add to the cluster.

Default:
  • no EC2 capacity will be added, you can use addCapacity to add capacity later.

cluster_name

The name for the cluster.

Default:

CloudFormation-generated name

container_insights

If true CloudWatch Container Insights will be enabled for the cluster.

Default:
  • Container Insights will be disabled for this cluster.

default_cloud_map_namespace

The service discovery namespace created in this cluster.

Default:

  • no service discovery namespace created, you can use addDefaultCloudMapNamespace to add a

default service discovery namespace later.

enable_fargate_capacity_providers

Whether to enable Fargate Capacity Providers.

Default:

false

execute_command_configuration

The execute command configuration for the cluster.

Default:
  • no configuration will be provided.

vpc

The VPC where your ECS instances will be running or your ENIs will be deployed.

Default:
  • creates a new VPC with two AZs