Class AsgCapacityProvider
An Auto Scaling Group Capacity Provider.
Inherited Members
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.AWS.ECS.dll
Syntax (csharp)
public class AsgCapacityProvider : Construct, IConstruct, IDependable
Syntax (vb)
Public Class AsgCapacityProvider
Inherits Construct
Implements IConstruct, IDependable
Remarks
This allows an ECS cluster to target a specific EC2 Auto Scaling Group for the placement of tasks. Optionally (and recommended), ECS can manage the number of instances in the ASG to fit the tasks, and can ensure that instances are not prematurely terminated while there are still tasks running on them.
ExampleMetadata: infused
Examples
Vpc vpc;
var cluster = new Cluster(this, "Cluster", new ClusterProps {
Vpc = vpc
});
var autoScalingGroup = new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
Vpc = vpc,
InstanceType = new InstanceType("t2.micro"),
MachineImage = EcsOptimizedImage.AmazonLinux2(),
MinCapacity = 0,
MaxCapacity = 100
});
var capacityProvider = new AsgCapacityProvider(this, "AsgCapacityProvider", new AsgCapacityProviderProps {
AutoScalingGroup = autoScalingGroup
});
cluster.AddAsgCapacityProvider(capacityProvider);
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,
CapacityProviderStrategies = new [] { new CapacityProviderStrategy {
CapacityProvider = capacityProvider.CapacityProviderName,
Weight = 1
} }
});
Synopsis
Constructors
AsgCapacityProvider(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
AsgCapacityProvider(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
AsgCapacityProvider(Construct, String, IAsgCapacityProviderProps) |
Properties
AutoScalingGroup | Auto Scaling Group. |
CanContainersAccessInstanceRole | Specifies whether the containers can access the container instance role. |
CapacityProviderName | Capacity provider name. |
EnableManagedTerminationProtection | Whether managed termination protection is enabled. |
MachineImageType | Auto Scaling Group machineImageType. |
Constructors
AsgCapacityProvider(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected AsgCapacityProvider(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
AsgCapacityProvider(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected AsgCapacityProvider(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
AsgCapacityProvider(Construct, String, IAsgCapacityProviderProps)
public AsgCapacityProvider(Construct scope, string id, IAsgCapacityProviderProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IAsgCapacityProviderProps
Properties
AutoScalingGroup
Auto Scaling Group.
public virtual AutoScalingGroup AutoScalingGroup { get; }
Property Value
CanContainersAccessInstanceRole
Specifies whether the containers can access the container instance role.
public virtual Nullable<bool> CanContainersAccessInstanceRole { get; }
Property Value
System.Nullable<System.Boolean>
Remarks
Default: false
CapacityProviderName
Capacity provider name.
public virtual string CapacityProviderName { get; }
Property Value
System.String
Remarks
Default: Chosen by CloudFormation
EnableManagedTerminationProtection
Whether managed termination protection is enabled.
public virtual Nullable<bool> EnableManagedTerminationProtection { get; }
Property Value
System.Nullable<System.Boolean>
MachineImageType
Auto Scaling Group machineImageType.
public virtual MachineImageType MachineImageType { get; }
Property Value