AWS Amazon ECS Cluster
This page shows how to write Terraform and CloudFormation for Amazon ECS Cluster and write them securely.
aws_ecs_cluster (Terraform)
The Cluster in Amazon ECS can be configured in Terraform with the resource name aws_ecs_cluster
. The following sections describe 4 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_ecs_cluster" "qa" {
name = "QA"
}
resource "aws_ecs_cluster" "Prod" {
name = "Prod"
resource "aws_ecs_cluster" "ecs1" {
name = "ecs1"
capacity_providers = ["FARGATE"]
}
resource "aws_ecs_task_definition" "ecs_task1" {
resource "aws_ecs_cluster" "repgram-front" {
name = "repgram-front"
}
resource "aws_ecs_cluster" "repgram-backend" {
name = "repgram-backend"
resource "aws_ecs_cluster" "denied" {
}
resource "aws_ecs_cluster" "denied_2" {
setting {
name = "containerInsights"
Security Best Practices for aws_ecs_cluster
There is 1 setting in aws_ecs_cluster that should be taken care of for security reasons. The following section explain an overview and example code.
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.
Parameters
-
arn
optional computed - string -
capacity_providers
optional - set of string -
id
optional computed - string -
name
required - string -
tags
optional - map from string to string -
default_capacity_provider_strategy
set block-
base
optional - number -
capacity_provider
required - string -
weight
optional - number
-
-
setting
set block
Explanation in Terraform Registry
Provides an ECS cluster.
Tips: Best Practices for The Other AWS Amazon ECS Resources
In addition to the aws_ecs_task_definition, 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_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::Cluster (CloudFormation)
The Cluster in ECS can be configured in CloudFormation with the resource name AWS::ECS::Cluster
. The following sections describe 6 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::ECS::Cluster
Properties:
ClusterName: jonathans-cluster
# AWS::ECS::Cluster for DEVELOP
# ------------------------------------------------------------#
ECSClusterForDevelop:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: !Sub ${ProjectName}-develop
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: !Sub '${EnvironmentName}_${AppClusterName}'
ClusterSettings:
- Name: 'containerInsights'
Value: 'disabled'
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: !Sub '${EnvironmentName}_${AppClusterName}'
ClusterSettings:
- Name: 'containerInsights'
Value: 'disabled'
Type: AWS::ECS::Cluster
Properties:
CapacityProviders: ['FARGATE', 'FARGATE_SPOT']
Tags:
- Key: Name
Value: !Sub "${PJPrefix}-${TagSuffix}-production"
"Type":"AWS::ECS::Cluster",
"Properties":{
"ClusterName":{
"Fn::Sub":"${NameTag}-${Environment}-WEB-CLUSTER"
}
}
Parameters
-
Tags
optional - List of Tag -
ClusterName
optional - String -
ClusterSettings
optional - List of ClusterSettings -
Configuration
optional - ClusterConfiguration -
CapacityProviders
optional - List -
DefaultCapacityProviderStrategy
optional - List of CapacityProviderStrategyItem
Explanation in CloudFormation Registry
The
AWS::ECS::Cluster
resource creates an Amazon Elastic Container Service (Amazon ECS) cluster.
Frequently asked questions
What is AWS Amazon ECS Cluster?
AWS Amazon ECS Cluster 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 Cluster?
For Terraform, the lciamp/terra-test, gilyas/infracost and DaichiHoshina/go_react_app source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the jonathanschoeller/jonathan-aws, TheGK-rh/CloudFormation and kybrdbnd/devops-hiring-challenge source code examples are useful. See the CloudFormation Example section for further details.