interface ManagedInstancesCapacityProviderProps
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ECS.ManagedInstancesCapacityProviderProps |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsecs#ManagedInstancesCapacityProviderProps |
![]() | software.amazon.awscdk.services.ecs.ManagedInstancesCapacityProviderProps |
![]() | aws_cdk.aws_ecs.ManagedInstancesCapacityProviderProps |
![]() | aws-cdk-lib » aws_ecs » ManagedInstancesCapacityProviderProps |
The options for creating a Managed Instances Capacity Provider.
Example
declare const vpc: ec2.Vpc;
declare const infrastructureRole: iam.Role;
declare const instanceProfile: iam.InstanceProfile;
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
// Create a Managed Instances Capacity Provider
const miCapacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'MICapacityProvider', {
infrastructureRole,
ec2InstanceProfile: instanceProfile,
subnets: vpc.privateSubnets,
securityGroups: [new ec2.SecurityGroup(this, 'MISecurityGroup', { vpc })],
instanceRequirements: {
vCpuCountMin: 1,
memoryMin: Size.gibibytes(2),
cpuManufacturers: [ec2.CpuManufacturer.INTEL],
acceleratorManufacturers: [ec2.AcceleratorManufacturer.NVIDIA],
},
propagateTags: ecs.PropagateManagedInstancesTags.CAPACITY_PROVIDER,
});
// Add the capacity provider to the cluster
cluster.addManagedInstancesCapacityProvider(miCapacityProvider);
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memoryReservationMiB: 256,
});
new ecs.Ec2Service(this, 'EC2Service', {
cluster,
taskDefinition,
minHealthyPercent: 100,
capacityProviderStrategies: [
{
capacityProvider: miCapacityProvider.capacityProviderName,
weight: 1,
},
],
});
Properties
Name | Type | Description |
---|---|---|
ec2 | IInstance | The EC2 instance profile that will be attached to instances launched by this capacity provider. |
subnets | ISubnet [] | The VPC subnets where EC2 instances will be launched. |
capacity | string | The name of the capacity provider. |
infrastructure | IRole | The IAM role that ECS uses to manage the infrastructure for the capacity provider. |
instance | Instance | The instance requirements configuration for EC2 instance selection. |
monitoring? | Instance | The CloudWatch monitoring configuration for the EC2 instances. |
propagate | Propagate | Specifies whether to propagate tags from the capacity provider to the launched instances. |
security | ISecurity [] | The security groups to associate with the launched EC2 instances. |
task | Size | The size of the task volume storage attached to each instance. |
ec2InstanceProfile
Type:
IInstance
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
Type:
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.
capacityProviderName?
Type:
string
(optional, default: CloudFormation-generated name)
The name of the capacity provider.
If a name is specified, it cannot start with aws
, ecs
, or fargate
.
If no name is specified, a default name in the CFNStackName-CFNResourceName-RandomString format is used.
If the stack name starts with aws
, ecs
, or fargate
, a unique resource name
is generated that starts with cp-
.
infrastructureRole?
Type:
IRole
(optional, default: A new role will be created with the AmazonECSInfrastructureRolePolicyForManagedInstances managed policy)
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.
instanceRequirements?
Type:
Instance
(optional, default: no specific instance requirements, ECS will choose appropriate instances)
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.
monitoring?
Type:
Instance
(optional, default: no enhanced monitoring (basic monitoring only))
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.
propagateTags?
Type:
Propagate
(optional, default: PropagateManagedInstancesTags.NONE - no tag propagation)
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.
securityGroups?
Type:
ISecurity
[]
(optional, default: default security group of the VPC)
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.
taskVolumeStorage?
Type:
Size
(optional, default: Size.gibibytes(80))
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.