Show / Hide Table of Contents

Class ManagedInstancesCapacityProviderProps

The options for creating a Managed Instances Capacity Provider.

Inheritance
object
ManagedInstancesCapacityProviderProps
Implements
IManagedInstancesCapacityProviderProps
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class ManagedInstancesCapacityProviderProps : IManagedInstancesCapacityProviderProps
Syntax (vb)
Public Class ManagedInstancesCapacityProviderProps Implements IManagedInstancesCapacityProviderProps
Remarks

ExampleMetadata: infused

Examples
Vpc vpc;
            Role infrastructureRole;
            InstanceProfile instanceProfile;


            var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });

            // Create a Managed Instances Capacity Provider
            var miCapacityProvider = new ManagedInstancesCapacityProvider(this, "MICapacityProvider", new ManagedInstancesCapacityProviderProps {
                InfrastructureRole = infrastructureRole,
                Ec2InstanceProfile = instanceProfile,
                Subnets = vpc.PrivateSubnets,
                SecurityGroups = new [] { new SecurityGroup(this, "MISecurityGroup", new SecurityGroupProps { Vpc = vpc }) },
                InstanceRequirements = new InstanceRequirementsConfig {
                    VCpuCountMin = 1,
                    MemoryMin = Size.Gibibytes(2),
                    CpuManufacturers = new [] { CpuManufacturer.INTEL },
                    AcceleratorManufacturers = new [] { AcceleratorManufacturer.NVIDIA }
                },
                PropagateTags = PropagateManagedInstancesTags.CAPACITY_PROVIDER
            });

            // Add the capacity provider to the cluster
            cluster.AddManagedInstancesCapacityProvider(miCapacityProvider);

            var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");

            taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
                Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
                MemoryReservationMiB = 256
            });

            new Ec2Service(this, "EC2Service", new Ec2ServiceProps {
                Cluster = cluster,
                TaskDefinition = taskDefinition,
                MinHealthyPercent = 100,
                CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
                    CapacityProvider = miCapacityProvider.CapacityProviderName,
                    Weight = 1
                } }
            });

Synopsis

Constructors

ManagedInstancesCapacityProviderProps()

The options for creating a Managed Instances Capacity Provider.

Properties

CapacityProviderName

The name of the capacity provider.

Ec2InstanceProfile

The EC2 instance profile that will be attached to instances launched by this capacity provider.

InfrastructureRole

The IAM role that ECS uses to manage the infrastructure for the capacity provider.

InstanceRequirements

The instance requirements configuration for EC2 instance selection.

Monitoring

The CloudWatch monitoring configuration for the EC2 instances.

PropagateTags

Specifies whether to propagate tags from the capacity provider to the launched instances.

SecurityGroups

The security groups to associate with the launched EC2 instances.

Subnets

The VPC subnets where EC2 instances will be launched.

TaskVolumeStorage

The size of the task volume storage attached to each instance.

Constructors

ManagedInstancesCapacityProviderProps()

The options for creating a Managed Instances Capacity Provider.

public ManagedInstancesCapacityProviderProps()
Remarks

ExampleMetadata: infused

Examples
Vpc vpc;
            Role infrastructureRole;
            InstanceProfile instanceProfile;


            var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });

            // Create a Managed Instances Capacity Provider
            var miCapacityProvider = new ManagedInstancesCapacityProvider(this, "MICapacityProvider", new ManagedInstancesCapacityProviderProps {
                InfrastructureRole = infrastructureRole,
                Ec2InstanceProfile = instanceProfile,
                Subnets = vpc.PrivateSubnets,
                SecurityGroups = new [] { new SecurityGroup(this, "MISecurityGroup", new SecurityGroupProps { Vpc = vpc }) },
                InstanceRequirements = new InstanceRequirementsConfig {
                    VCpuCountMin = 1,
                    MemoryMin = Size.Gibibytes(2),
                    CpuManufacturers = new [] { CpuManufacturer.INTEL },
                    AcceleratorManufacturers = new [] { AcceleratorManufacturer.NVIDIA }
                },
                PropagateTags = PropagateManagedInstancesTags.CAPACITY_PROVIDER
            });

            // Add the capacity provider to the cluster
            cluster.AddManagedInstancesCapacityProvider(miCapacityProvider);

            var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");

            taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
                Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
                MemoryReservationMiB = 256
            });

            new Ec2Service(this, "EC2Service", new Ec2ServiceProps {
                Cluster = cluster,
                TaskDefinition = taskDefinition,
                MinHealthyPercent = 100,
                CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
                    CapacityProvider = miCapacityProvider.CapacityProviderName,
                    Weight = 1
                } }
            });

Properties

CapacityProviderName

The name of the capacity provider.

public string? CapacityProviderName { get; set; }
Property Value

string

Remarks

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-.

Default: CloudFormation-generated name

Ec2InstanceProfile

The EC2 instance profile that will be attached to instances launched by this capacity provider.

public IInstanceProfile Ec2InstanceProfile { get; set; }
Property Value

IInstanceProfile

Remarks

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.

InfrastructureRole

The IAM role that ECS uses to manage the infrastructure for the capacity provider.

public IRole? InfrastructureRole { get; set; }
Property Value

IRole

Remarks

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 policy

InstanceRequirements

The instance requirements configuration for EC2 instance selection.

public IInstanceRequirementsConfig? InstanceRequirements { get; set; }
Property Value

IInstanceRequirementsConfig

Remarks

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

Monitoring

The CloudWatch monitoring configuration for the EC2 instances.

public InstanceMonitoring? Monitoring { get; set; }
Property Value

InstanceMonitoring?

Remarks

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)

PropagateTags

Specifies whether to propagate tags from the capacity provider to the launched instances.

public PropagateManagedInstancesTags? PropagateTags { get; set; }
Property Value

PropagateManagedInstancesTags?

Remarks

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 propagation

SecurityGroups

The security groups to associate with the launched EC2 instances.

public ISecurityGroup[]? SecurityGroups { get; set; }
Property Value

ISecurityGroup[]

Remarks

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 VPC

Subnets

The VPC subnets where EC2 instances will be launched.

public ISubnet[] Subnets { get; set; }
Property Value

ISubnet[]

Remarks

This array must be non-empty and should contain subnets from the VPC where you want the managed instances to be deployed.

TaskVolumeStorage

The size of the task volume storage attached to each instance.

public Size? TaskVolumeStorage { get; set; }
Property Value

Size

Remarks

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)

Implements

IManagedInstancesCapacityProviderProps
Back to top Generated by DocFX