AWS Amazon ECS Capacity Provider
This page shows how to write Terraform and CloudFormation for Amazon ECS Capacity Provider and write them securely.
aws_ecs_capacity_provider (Terraform)
The Capacity Provider in Amazon ECS can be configured in Terraform with the resource name aws_ecs_capacity_provider
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_ecs_capacity_provider" "cluster_capacity" {
name = "test"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.cluster.arn
managed_termination_protection = "ENABLED"
resource "aws_ecs_capacity_provider" "capacity_provider" {
name = var.name
auto_scaling_group_provider {
auto_scaling_group_arn = var.auto_scaling_group_arn
managed_termination_protection = "ENABLED"
managed_scaling {
resource "aws_ecs_capacity_provider" "cp" {
name = "capacity-provider-dask"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.asg.arn
managed_termination_protection = "DISABLED"
resource "aws_ecs_capacity_provider" "tmp-cluster-ec2" {
# Currentry, we cannot delete capacity provider. If you exec 'terraform destroy', you can delete resouce only on tfstate.
name = "tmp-cluster-ec2"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.tmp-asg.arn
resource "aws_ecs_capacity_provider" "this" {
name = local.envname
auto_scaling_group_provider {
auto_scaling_group_arn = module.asg.autoscaling_group_arn
}
Parameters
-
arn
optional computed - string -
id
optional computed - string -
name
required - string -
tags
optional - map from string to string -
auto_scaling_group_provider
list block-
auto_scaling_group_arn
required - string -
managed_termination_protection
optional computed - string -
managed_scaling
list block-
instance_warmup_period
optional computed - number -
maximum_scaling_step_size
optional computed - number -
minimum_scaling_step_size
optional computed - number -
status
optional computed - string -
target_capacity
optional computed - number
-
-
Explanation in Terraform Registry
Provides an ECS cluster capacity provider. More information can be found on the ECS Developer Guide.
NOTE: Associating an ECS Capacity Provider to an Auto Scaling Group will automatically add the
AmazonECSManaged
tag to the Auto Scaling Group. This tag should be included in theaws_autoscaling_group
resource configuration to prevent Terraform from removing it in subsequent executions as well as ensuring theAmazonECSManaged
tag is propagated to all EC2 Instances in the Auto Scaling Group ifmin_size
is above 0 on creation. Any EC2 Instances in the Auto Scaling Group without this tag must be manually be updated, otherwise they may cause unexpected scaling behavior and metrics.
Tips: Best Practices for The Other AWS Amazon ECS Resources
In addition to the aws_ecs_cluster, AWS Amazon ECS has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_ecs_cluster
Ensure to enable CloudWatch Container Insights
It's better to enable CloudWatch Container Insights to gain a better perspective on cluster applications. CloudWatch Container Insights collects, aggregates, and summarizes ECS metrics and logs.
aws_ecs_task_definition
Ensure to enable in-transit encryption of EFS volume
It is better to enable in-transit encryption of EFS volume for the protection of data in transit more.
AWS::ECS::CapacityProvider (CloudFormation)
The CapacityProvider in ECS can be configured in CloudFormation with the resource name AWS::ECS::CapacityProvider
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::ECS::CapacityProvider
DependsOn: ECSCluster
Condition: EC2
Properties:
AutoScalingGroupProvider:
AutoScalingGroupArn: !Ref ECSAutoScalingGroup
Type: AWS::ECS::CapacityProvider
Properties:
AutoScalingGroupProvider:
AutoScalingGroupArn:
Fn::ImportValue: !Sub ${Service}-${AccountType}-asg
ManagedScaling:
Type: AWS::ECS::CapacityProvider
Properties:
AutoScalingGroupProvider:
AutoScalingGroupArn: !Ref ECSAutoScalingGroupOD
ManagedScaling:
MaximumScalingStepSize: 10
Type: AWS::ECS::CapacityProvider
Properties:
AutoScalingGroupProvider:
AutoScalingGroupArn: !ImportValue AutoScalingGroup01
ManagedScaling:
MaximumScalingStepSize: 1
# Type: AWS::ECS::CapacityProvider
# Properties:
# AutoScalingGroupProvider:
# AutoScalingGroupArn: !Ref ECSAutoScalingGroup
# #Fn::GetAtt:
# # - ECSAutoScalingGroup
"Type": "AWS::ECS::CapacityProvider",
"Properties": {
"AutoScalingGroupProvider": {
"AutoScalingGroupArn": {
"Ref": "ASG46ED3070"
},
"Type": "AWS::ECS::CapacityProvider",
"Properties": {
"AutoScalingGroupProvider": {
"AutoScalingGroupArn": {
"Ref": "ASG46ED3070"
},
"Type": "AWS::ECS::CapacityProvider",
"Properties": {
"AutoScalingGroupProvider": {
"AutoScalingGroupArn": {
"Ref": "ASG46ED3070"
},
"Type": "AWS::ECS::CapacityProvider",
"Properties": {
"AutoScalingGroupProvider": {
"AutoScalingGroupArn": {
"Ref": "ASG46ED3070"
},
"AWS::ECS::CapacityProvider.ManagedScaling": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-capacityprovider-managedscaling.html",
"Properties": {
"MinimumScalingStepSize": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-capacityprovider-managedscaling.html#cfn-ecs-capacityprovider-managedscaling-minimumscalingstepsize",
"UpdateType": "Immutable",
Parameters
-
AutoScalingGroupProvider
required - AutoScalingGroupProvider -
Name
optional - String -
Tags
optional - List of Tag
Explanation in CloudFormation Registry
The
AWS::ECS::CapacityProvider
resource creates an Amazon Elastic Container Service (Amazon ECS) capacity provider. Capacity providers are associated with an Amazon ECS cluster and are used in capacity provider strategies to facilitate cluster auto scaling.Only capacity providers using an Auto Scaling group can be created. Amazon ECS tasks on AWS Fargate use the
FARGATE
andFARGATE_SPOT
capacity providers which are already created and available to all accounts in Regions supported by AWS Fargate.
Frequently asked questions
What is AWS Amazon ECS Capacity Provider?
AWS Amazon ECS Capacity Provider is a resource for Amazon ECS of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon ECS Capacity Provider?
For Terraform, the MiguelIsaza95/movie-analyst-containers, balu970/Terraform-modules and b0gdanp3trovic/dask_on_ecs_terraform source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the ebosas/microservices, kame8015/asg-tutorial and gaonkarr/ECS-Cost-Strategies source code examples are useful. See the CloudFormation Example section for further details.