ManagedInstancesCapacityProviderProps Struct
The options for creating a Managed Instances Capacity Provider.
Example
declare const vpc: ec2.Vpc;
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc,
description: 'Security group for managed instances',
});
const miCapacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'MICapacityProvider', {
capacityOptionType: ecs.CapacityOptionType.SPOT,
subnets: vpc.privateSubnets,
securityGroups: [securityGroup],
instanceRequirements: {
vCpuCountMin: 1,
memoryMin: Size.gibibytes(2),
},
});
// Optionally configure security group rules using IConnectable interface
miCapacityProvider.connections.allowFrom(ec2.Peer.ipv4(vpc.vpcCidrBlock), ec2.Port.tcp(80));
// Add the capacity provider to the cluster
cluster.addManagedInstancesCapacityProvider(miCapacityProvider);
const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
memoryMiB: '512',
cpu: '256',
networkMode: ecs.NetworkMode.AWS_VPC,
compatibility: ecs.Compatibility.MANAGED_INSTANCES,
});
taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memoryReservationMiB: 256,
});
new ecs.FargateService(this, 'FargateService', {
cluster,
taskDefinition,
minHealthyPercent: 100,
capacityProviderStrategies: [
{
capacityProvider: miCapacityProvider.capacityProviderName,
weight: 1,
},
],
});
Properties
capacityOptionTypeCapacityOptionTypecapacity_option_typeCapacityOptionTypecapacityOptionTypeCapacityOptionTypeCapacityOptionTypeCapacityOptionTypeCapacityOptionTypeCapacityOptionType= `ON_DEMAND`#This determines whether instances are launched as On-Demand or Spot instances.
capacityProviderNamestringcapacity_provider_namestrcapacityProviderNameStringCapacityProviderNamestringCapacityProviderName*string= CloudFormation-generated name#notes
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-.
ec2InstanceProfileIInstanceProfileec2_instance_profileIInstanceProfileec2InstanceProfileIInstanceProfileEc2InstanceProfileIInstanceProfileEc2InstanceProfileIInstanceProfile= A new instance profile prefixed …#notes · default
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.
If you are using Amazon ECS Managed Instances with the AWS-managed Infrastructure policy (AmazonECSInfrastructureRolePolicyForManagedInstances), the instance profile must be prefixed with ecsInstanceRole for the built in PassRole policy to apply.
If you are using a custom policy for the Infrastructure role, the instance profile can have an alternative name.
Default: A new instance profile prefixed with 'ecsInstanceRole' will be created
infrastructureRoleIRoleinfrastructure_roleIRoleinfrastructureRoleIRoleInfrastructureRoleIRoleInfrastructureRoleIRole= A new role will be created with …#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
Default: A new role will be created with the AmazonECSInfrastructureRolePolicyForManagedInstances managed policy
instanceRequirementsInstanceRequirementsConfiginstance_requirementsInstanceRequirementsConfiginstanceRequirementsInstanceRequirementsConfigInstanceRequirementsInstanceRequirementsConfigInstanceRequirementsInstanceRequirementsConfig= no specific instance requirement…#notes · default
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 instances
monitoringInstanceMonitoringmonitoringInstanceMonitoringmonitoringInstanceMonitoringMonitoringInstanceMonitoringMonitoringInstanceMonitoring= no enhanced monitoring (basic mo…#Determines the granularity of CloudWatch metrics collection for the instances. Detailed monitoring incurs additional costs but provides better observability.
default
Default: no enhanced monitoring (basic monitoring only)
propagateTagsPropagateManagedInstancesTagspropagate_tagsPropagateManagedInstancesTagspropagateTagsPropagateManagedInstancesTagsPropagateTagsPropagateManagedInstancesTagsPropagateTagsPropagateManagedInstancesTags= PropagateManagedInstancesTags.NO…#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
Default: PropagateManagedInstancesTags.NONE - no tag propagation
securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGrouprequired#These security groups control the network traffic allowed to and from the instances.
subnetsISubnet[]subnetstyping.List[ISubnet]subnetsList<ISubnet>SubnetsISubnet[]Subnets*[]ISubnetrequired#This array must be non-empty and should contain subnets from the VPC where you want the managed instances to be deployed.
taskVolumeStorageSizetask_volume_storageSizetaskVolumeStorageSizeTaskVolumeStorageSizeTaskVolumeStorageSize= Size.gibibytes(80)#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.