{"id":1551,"date":"2020-07-23T16:07:19","date_gmt":"2020-07-23T14:07:19","guid":{"rendered":"https:\/\/blog.besharp.it\/?p=1551"},"modified":"2021-03-24T12:01:53","modified_gmt":"2021-03-24T11:01:53","slug":"deploy-a-docker-compose-application-inside-an-aws-environment-new-with-ecs-cli","status":"publish","type":"post","link":"https:\/\/blog.besharp.it\/deploy-a-docker-compose-application-inside-an-aws-environment-new-with-ecs-cli\/","title":{"rendered":"Deploy of a Docker-compose application in an AWS environment using ECS CLI"},"content":{"rendered":"
Nowadays, using Docker as an infrastructure container for local testing purposes is becoming more and more common. Many times developers exploit docker-compose functionality to create an infrastructure stack that contains their application, web server, and databases in different docker containers.<\/span><\/p>\n
In this article, you will learn how to deploy an entire solution inside your AWS environment using AWS ECS Fargate service. Let’s start by explaining what AWS ECS Fargate is.<\/span><\/p>\n
Amazon ECS and AWS Fargate in a nutshell<\/b><\/h2>\n
Amazon ECS is a service that allows you to run and manage clusters of Docker containers. It\u2019s fully managed by Amazon and easily scalable based on your traffic load.\u00a0<\/span><\/p>\n
It comes in two possible flavors:<\/span><\/p>\n
\n
EC2 instances hosting your containers: with this configuration, EC2 instances scaling policies are managed by the developer.<\/span><\/li>\n
Fargate mode: automatically manages your containers, providing the correct computational resources to your application.<\/span><\/li>\n<\/ul>\n
AWS ECS three main actors are:<\/span><\/p>\n\n
Cluster<\/b>: the logical grouping of ECS resources.<\/span><\/li>\n
Service<\/b>: resource that allows you to run and maintain a specified number of instances of a task definition simultaneously, in an Amazon ECS cluster.<\/span><\/li>\n
Task-Definition<\/b>: a text file, in JSON format, that contains all the definitions and configurations of your containers.<\/span><\/li>\n<\/ol>\n
Now that you\u2019ve learned what AWS ECS Fargate is, let’s try some hands-on.<\/span><\/p>\n
Convert Docker containers to Fargate Task Definition<\/b><\/h2>\n
Before starting to create resources inside the AWS environment, you have to split your docker defined inside the docker-compose file. To do this, some considerations must be made.\u00a0<\/span><\/p>\n
Approaching Database deployment<\/b><\/h3>\n
If you have some databases inside your docker-compose, it is highly recommended to consider the adoption of the right AWS managed service, for example AWS RDS for relational databases, AWS DynamoDB for non-relational databases, or AWS ElastiCache for cache databases.\u00a0<\/span><\/p>\n
Follow a Stateless approach instead of a Stateful one.<\/b><\/h3>\n
To reach scalability, a stateless approach should be used: this means that two requests of the same user session can be executed on different instances of your container application.<\/span><\/p>\n
Let\u2019s start creating all the AWS services you need to build your application. For AWS Fargate we have already discussed all steps needed to create a cluster and services <\/span>in this article<\/span><\/a>.<\/span><\/p>\n