ManagedInstancesCapacityProvider
- class aws_cdk.aws_ecs.ManagedInstancesCapacityProvider(scope, id, *, ec2_instance_profile, subnets, capacity_provider_name=None, infrastructure_role=None, instance_requirements=None, monitoring=None, propagate_tags=None, security_groups=None, task_volume_storage=None)
Bases:
Construct
A Managed Instances Capacity Provider.
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
- ExampleMetadata:
infused
Example:
# vpc: ec2.Vpc # infrastructure_role: iam.Role # instance_profile: iam.InstanceProfile cluster = ecs.Cluster(self, "Cluster", vpc=vpc) # Create a Managed Instances Capacity Provider mi_capacity_provider = ecs.ManagedInstancesCapacityProvider(self, "MICapacityProvider", infrastructure_role=infrastructure_role, ec2_instance_profile=instance_profile, subnets=vpc.private_subnets, security_groups=[ec2.SecurityGroup(self, "MISecurityGroup", vpc=vpc)], instance_requirements=ec2.InstanceRequirementsConfig( v_cpu_count_min=1, memory_min=Size.gibibytes(2), cpu_manufacturers=[ec2.CpuManufacturer.INTEL], accelerator_manufacturers=[ec2.AcceleratorManufacturer.NVIDIA] ), propagate_tags=ecs.PropagateManagedInstancesTags.CAPACITY_PROVIDER ) # Add the capacity provider to the cluster cluster.add_managed_instances_capacity_provider(mi_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, min_healthy_percent=100, capacity_provider_strategies=[ecs.CapacityProviderStrategy( capacity_provider=mi_capacity_provider.capacity_provider_name, weight=1 ) ] )
- Parameters:
scope (
Construct
)id (
str
)ec2_instance_profile (
IInstanceProfile
) – The EC2 instance profile that will be attached to instances launched by this capacity provider. This instance profile must contain the necessary IAM permissions for ECS container instances to register with the cluster and run tasks. At minimum, it should include permissions for ECS agent communication, ECR image pulling, and CloudWatch logging.subnets (
Sequence
[ISubnet
]) – The VPC subnets where EC2 instances will be launched. This array must be non-empty and should contain subnets from the VPC where you want the managed instances to be deployed.capacity_provider_name (
Optional
[str
]) – The name of the capacity provider. If a name is specified, it cannot start withaws
,ecs
, orfargate
. If no name is specified, a default name in the CFNStackName-CFNResourceName-RandomString format is used. If the stack name starts withaws
,ecs
, orfargate
, a unique resource name is generated that starts withcp-
. Default: CloudFormation-generated nameinfrastructure_role (
Optional
[IRole
]) – The IAM role that ECS uses to manage the infrastructure for the capacity provider. This role is used by ECS to perform actions such as launching and terminating instances, managing Auto Scaling Groups, and other infrastructure operations required for the managed instances capacity provider. Default: - A new role will be created with the AmazonECSInfrastructureRolePolicyForManagedInstances managed policyinstance_requirements (
Union
[InstanceRequirementsConfig
,Dict
[str
,Any
],None
]) – The instance requirements configuration for EC2 instance selection. This allows you to specify detailed requirements for instance selection including vCPU count ranges, memory ranges, CPU manufacturers (Intel, AMD, AWS Graviton), instance generations, network performance requirements, and many other criteria. ECS will automatically select appropriate instance types that meet these requirements. Default: - no specific instance requirements, ECS will choose appropriate instancesmonitoring (
Optional
[InstanceMonitoring
]) – The CloudWatch monitoring configuration for the EC2 instances. Determines the granularity of CloudWatch metrics collection for the instances. Detailed monitoring incurs additional costs but provides better observability. Default: - no enhanced monitoring (basic monitoring only)propagate_tags (
Optional
[PropagateManagedInstancesTags
]) – Specifies whether to propagate tags from the capacity provider to the launched instances. When set to CAPACITY_PROVIDER, tags applied to the capacity provider resource will be automatically applied to all EC2 instances launched by this capacity provider. Default: PropagateManagedInstancesTags.NONE - no tag propagationsecurity_groups (
Optional
[Sequence
[ISecurityGroup
]]) – The security groups to associate with the launched EC2 instances. These security groups control the network traffic allowed to and from the instances. If not specified, the default security group of the VPC containing the subnets will be used. Default: - default security group of the VPCtask_volume_storage (
Optional
[Size
]) – The size of the task volume storage attached to each instance. This storage is used for container images, container logs, and temporary files. Larger storage may be needed for workloads with large container images or applications that generate significant temporary data. Default: Size.gibibytes(80)
Methods
- bind(cluster)
Associates the capacity provider with the specified cluster.
This method is called by the cluster when adding the capacity provider.
- Parameters:
cluster (
ICluster
)- Return type:
None
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- PROPERTY_INJECTION_ID = 'aws-cdk-lib.aws-ecs.ManagedInstancesCapacityProvider'
- capacity_provider_name
Capacity provider name.
- node
The tree node.
Static Methods
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.