Now that you have an overview of the ECS cluster provisioning process, let's step through the configuration required to get an ECS cluster up and running.
As indicated in the deployment overview, you will be using CloudFormation to create your resources in an infrastructure-as-code manner, and because you are right at the start of this journey, you first need to create this CloudFormation template, which I will assume you are defining in a file called stack.yml at the root of the todobackend-aws repository you created earlier in Chapter 5 - Publishing Docker Images Using ECR, as demonstrated in the following example:
> touch stack.yml
> tree .
.
├── ecr.yml
└── stack.yml
0 directories, 2 files
You can now establish a skeleton CloudFormation template in the stack.yml file and create your ECS cluster resource:
AWSTemplateFormatVersion: "2010-09-09"
Description: Todobackend Application
Resources:
ApplicationCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: todobackend-cluster
As you can see in the preceding example, defining an ECS cluster is very simple, with the AWS::ECS::Cluster resource type only having a single optional property called ClusterName. After ensuring your environment is configured with the correct AWS profile, you can now create and deploy the stack using the aws cloudformation deploy command, and verify your cluster has been created by using the aws ecs list-clusters command, as demonstrated in the following example:
> export AWS_PROFILE=docker-in-aws
> aws cloudformation deploy --template-file stack.yml --stack-name todobackend
Enter MFA code for arn:aws:iam::385605022855:mfa/justin.menga:
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - todobackend
> aws ecs list-clusters
{
"clusterArns": [
"arn:aws:ecs:us-east-1:385605022855:cluster/todobackend-cluster"
]
}