Class ManagedInstancesCapacityProvider
A Managed Instances Capacity Provider.
Implements
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class ManagedInstancesCapacityProvider : Construct, IConnectable
Syntax (vb)
Public Class ManagedInstancesCapacityProvider Inherits Construct Implements IConnectable
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Examples
Vpc vpc;
var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });
var securityGroup = new SecurityGroup(this, "SecurityGroup", new SecurityGroupProps {
Vpc = vpc,
Description = "Security group for managed instances"
});
var miCapacityProvider = new ManagedInstancesCapacityProvider(this, "MICapacityProvider", new ManagedInstancesCapacityProviderProps {
CapacityOptionType = CapacityOptionType.SPOT,
Subnets = vpc.PrivateSubnets,
SecurityGroups = new [] { securityGroup },
InstanceRequirements = new InstanceRequirementsConfig {
VCpuCountMin = 1,
MemoryMin = Size.Gibibytes(2)
}
});
// Optionally configure security group rules using IConnectable interface
miCapacityProvider.Connections.AllowFrom(Peer.Ipv4(vpc.VpcCidrBlock), Port.Tcp(80));
// Add the capacity provider to the cluster
cluster.AddManagedInstancesCapacityProvider(miCapacityProvider);
var taskDefinition = new TaskDefinition(this, "TaskDef", new TaskDefinitionProps {
MemoryMiB = "512",
Cpu = "256",
NetworkMode = NetworkMode.AWS_VPC,
Compatibility = Compatibility.MANAGED_INSTANCES
});
taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
MemoryReservationMiB = 256
});
new FargateService(this, "FargateService", new FargateServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
MinHealthyPercent = 100,
CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
CapacityProvider = miCapacityProvider.CapacityProviderName,
Weight = 1
} }
});
Synopsis
Constructors
| ManagedInstancesCapacityProvider(Construct, string, IManagedInstancesCapacityProviderProps) | A Managed Instances Capacity Provider. |
Properties
| CapacityProviderName | Capacity provider name. |
| Cluster | The cluster this capacity provider is associated with. |
| Connections | The network connections associated with this resource. |
| Ec2InstanceProfile | The EC2 instance profile attached to instances launched by this capacity provider. |
| InfrastructureRole | The IAM role that ECS uses to manage the infrastructure for the capacity provider. |
| PROPERTY_INJECTION_ID | Uniquely identifies this class. |
Methods
| Bind(ICluster) | Associates the capacity provider with the specified cluster. |
Constructors
ManagedInstancesCapacityProvider(Construct, string, IManagedInstancesCapacityProviderProps)
A Managed Instances Capacity Provider.
public ManagedInstancesCapacityProvider(Construct scope, string id, IManagedInstancesCapacityProviderProps props)
Parameters
- scope Construct
- id string
- props IManagedInstancesCapacityProviderProps
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Examples
Vpc vpc;
var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });
var securityGroup = new SecurityGroup(this, "SecurityGroup", new SecurityGroupProps {
Vpc = vpc,
Description = "Security group for managed instances"
});
var miCapacityProvider = new ManagedInstancesCapacityProvider(this, "MICapacityProvider", new ManagedInstancesCapacityProviderProps {
CapacityOptionType = CapacityOptionType.SPOT,
Subnets = vpc.PrivateSubnets,
SecurityGroups = new [] { securityGroup },
InstanceRequirements = new InstanceRequirementsConfig {
VCpuCountMin = 1,
MemoryMin = Size.Gibibytes(2)
}
});
// Optionally configure security group rules using IConnectable interface
miCapacityProvider.Connections.AllowFrom(Peer.Ipv4(vpc.VpcCidrBlock), Port.Tcp(80));
// Add the capacity provider to the cluster
cluster.AddManagedInstancesCapacityProvider(miCapacityProvider);
var taskDefinition = new TaskDefinition(this, "TaskDef", new TaskDefinitionProps {
MemoryMiB = "512",
Cpu = "256",
NetworkMode = NetworkMode.AWS_VPC,
Compatibility = Compatibility.MANAGED_INSTANCES
});
taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
MemoryReservationMiB = 256
});
new FargateService(this, "FargateService", new FargateServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
MinHealthyPercent = 100,
CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
CapacityProvider = miCapacityProvider.CapacityProviderName,
Weight = 1
} }
});
Properties
CapacityProviderName
Capacity provider name.
public virtual string CapacityProviderName { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Cluster
The cluster this capacity provider is associated with.
public virtual ICluster? Cluster { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Connections
The network connections associated with this resource.
public virtual Connections_ Connections { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Ec2InstanceProfile
The EC2 instance profile attached to instances launched by this capacity provider.
public virtual IInstanceProfile Ec2InstanceProfile { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
InfrastructureRole
The IAM role that ECS uses to manage the infrastructure for the capacity provider.
public virtual IRole InfrastructureRole { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
This allows an ECS cluster to use Managed Instances for task placement with managed infrastructure.
ExampleMetadata: infused
Methods
Bind(ICluster)
Associates the capacity provider with the specified cluster.
public virtual void Bind(ICluster cluster)
Parameters
- cluster ICluster
Remarks
This method is called by the cluster when adding the capacity provider.