Creating our production ECS cluster

Thanks to the upfront work we did with our CloudFormation templates, adding a new environment will be trivial.

We will start by launching a production ECS cluster, as shown in the following code:

$ aws cloudformation create-stack 
--stack-name production-cluster
--capabilities CAPABILITY_IAM
--template-body file://ecs-cluster-cf.template
--parameters
ParameterKey=KeyPair,ParameterValue=EffectiveDevOpsAWS
ParameterKey=VpcId,ParameterValue=vpc-f7dc4093
ParameterKey=PublicSubnet,ParameterValue=subnet-3e905948\,subnet-
4decfe66\,subnet-4f3bdb17\,subnet-82ba3fbf
{
"StackId": "arn:aws:cloudformation:us-east-1:511912822958:stack/production-
cluster/53833670-e519-11e6-aa35-50fae984a035"
}

We need to wait for the creation of the stack to complete as we need to get some of the exported values from the cluster creation. We can run the following command to get our Terminal to hang until we can crate our next stack:

$ aws cloudformation wait stack-create-complete 
--stack-name production-cluster

We move on to creating our ALB and waiting until completion:

$ aws cloudformation create-stack 
--stack-name production-alb
--capabilities CAPABILITY_IAM
--template-body file://helloworld-ecs-alb-cf.template
{
"StackId": "arn:aws:cloudformation:us-east-1:511912822958:stack/production-alb/08592870-e51a-11e6-ae6e-500c28b04cd1"
}

$ aws cloudformation wait stack-create-complete --stack-name production-alb

Finally, we can create our service, as shown in the following code:

$ aws cloudformation create-stack 
--stack-name production-helloworld-service
--capabilities CAPABILITY_IAM
--template-body file://helloworld-ecs-service-cf.template
--parameters
ParameterKey=Tag,ParameterValue=latest
{
"StackId": "arn:aws:cloudformation:us-east-1:511912822958:stack/production-helloworld-service/91a5ee60-e51a-11e6-a0f4-500c221b72d1"
}

$ aws cloudformation wait stack-create-complete
--stack-name production-helloworld-service

At this point, our production environment should be working. We can get its URL by looking at the output of the ALB stack creation and curl the endpoint to make sure the application is up and running:

$ aws cloudformation describe-stacks 
--stack-name production-alb
--query 'Stacks[0].Outputs'
[
{
"Description": "TargetGroup",
"OutputKey": "TargetGroup",
"OutputValue": "arn:aws:elasticloadbalancing:us-east-1:511912822958:targetgroup/produ-Targe-1WL80TIPA6T8A/02cf0b93549c04a4"
},
{
"Description": "Helloworld URL",
"OutputKey": "URL",
"OutputValue": "http://produ-LoadB-1NDDH03862MMQ-1994089665.us-east-1.elb.amazonaws.com:3000"
}
]
$ curl http://produ-LoadB-1NDDH03862MMQ-1994089665.us-east-1.elb.amazonaws.com:3000
Hello World

Now that our production environment is ready, we will look into automating the creation of containers. In order to accomplish that, we will rely on the CodeBuild service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset