Traditional Amazon ECS deployments on EC2 instances have a limitation on the number of Elastic Network Interfaces (ENIs) per instance. This restricts the number of tasks you can efficiently pack onto a single container instance, especially for microservices architectures with numerous lightweight tasks. Scaling your ECS cluster then requires more EC2 instances, increasing costs and management complexity.
Solution:
Amazon ECS offers an account setting called awsvpcTrunking that allows you to significantly increase the number of ENIs available on supported EC2 instance types. This enables you to pack more tasks onto each container instance, potentially reducing the overall number of instances needed in your cluster and leading to cost savings and simpler management.
There are Multiple ways you can enable this feature.
Lets start with How to Enable awsvpcTrunking using AWS Console: ?
- Go to the Amazon ECS service console.
- Navigate to the "Clusters" section and select your desired cluster.
- Click on the "Settings" tab.
- Under "Account Settings," locate "awsvpcTrunking."
- Set the value to "enabled" and click "Save."
How to Enable awsvpcTrunking using AWS CLI ?
aws ecs put-account-setting --name awsvpcTrunking --value enabled --region <your-region>
Replace <your-region> with the region you are using.
How to Enable awsvpcTrunking using Cloudformation ?
{
"Resources": {
"MyCluster": {
"Type": "AWS::ECS::Cluster",
"Properties": {
"ClusterName": "MyCluster",
"AccountSettings": [
{
"Name": "awsvpcTrunking",
"Value": "enabled"
}
]
}
}
}
}
How to Enable awsvpcTrunking using Terraform ?
resource "aws_ecs_cluster" "my_cluster" {
name = "MyCluster"
setting {
name = "awsvpcTrunking"
value = "enabled"
}
}
References:
Increasing Amazon ECS Linux container instance network interfaces: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html
Optimizing Amazon ECS task density using awsvpc network mode: https://aws.amazon.com/ecs/