Day 20 of 30 Days of AWS Series: Dive into the World of AWS ECS 🚀

Day 20 of 30 Days of AWS Series: Dive into the World of AWS ECS 🚀

✍Introduction:

Are you ready to explore the containerized world with Amazon ECS? In today's edition of our 30 Days of AWS series, we'll unravel the mysteries of ECS, its fundamentals, and why it might be your go-to container orchestration tool. 🛠️

What is AWS ECS?

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service that allows you to run the Docker container at scale. It eliminates the need to manage your own container orchestration infrastructure and provides a highly scalable, reliable, and secure environment for deploying and managing your applications.

Why Choose ECS Over Other Container Orchestration Tools?

Before diving deep into ECS, let's compare it with some popular alternatives like Kubernetes and Docker Swarm.

  • Comparison with Kubernetes:

Kubernetes is undoubtedly a powerful container orchestration tool with a vast ecosystem, but it comes with a steeper learning curve. ECS, on the other hand, offers a more straightforward setup and is tightly integrated with other AWS services, making it a preferred choice for AWS-centric environments.

  • Comparison with Docker Swarm:

Docker Swarm is relatively easy to set up and is suitable for small to medium-scale deployments. However, as your application grows, ECS outshines Docker Swarm in terms of scalability, reliability, and seamless integration with AWS features like IAM roles and CloudWatch.

✍ECS Components:

To understand ECS better, let's explore its core components:

  1. Clusters: A cluster is an essential part of ECS, offering a logical grouping of EC2 instances or Fargate tasks that allows you to run your containers with confidence and ease. It is the foundation of your deployment, ensuring that your services are deployed effectively and efficiently. With a cluster at your disposal, you can rest assured that your ECS environment is in good hands.

  2. Task Definitions: Task Definitions define how your container should run, including the docker image to use, CPU and memory requirements, networking and more. It is like a blueprint for your containers.

  3. Tasks: A task represents a single running instance of a task definition within a cluster. It could be a single container or multiple related containers that need to work together.

  4. Services: Services help you to maintain a specified number of running tasks simultaneously ensuring high availability and load balancing for your applications.

    dc

✍Pros of Using AWS ECS

  • Fully Managed Service: AWS handles the underlying infrastructure, making it easier for you to focus on deploying and managing applications.

  • Seamless Integration: ECS seamlessly integrates with other AWS services like IAM, CloudWatch, Load Balancers, and more.

  • Scalability: With support for Auto Scaling, ECS can automatically adjust the number of tasks based on demand.

  • Cost-Effective: You pay only for the AWS resources you use, and you can take advantage of cost optimization features.

✍Cons of Using AWS ECS

  • AWS-Centric: If you have a multi-cloud strategy or already invested heavily in another cloud provider, ECS's tight integration with AWS might be a limitation.

  • Learning Curve for Advanced Features: While basic usage is easy, utilizing more advanced features might require a deeper understanding.

  • Limited Flexibility: Although ECS can run non-Docker workloads with EC2 launch types, it is primarily optimized for Docker containers.

✍Installation and Configuration

Let's get our hands dirty and set up AWS ECS step-by-step.

  • Prerequisites:

    -- An AWS account with appropriate IAM permissions.

    -- The AWS CLI and ECS CLI are installed on your local machine

✍Installing ECS CLI in Windows:

  • Open Windows PowerShell and enter the following commands.

  • Note

    If you encounter permission issues, ensure that you have administrator access on Windows and you are running PowerShell as an administrator.

New-Item -Path 'C:\Program Files\Amazon\ECSCLI' -ItemType Directory
Invoke-WebRequest -OutFile 'C:\Program Files\Amazon\ECSCLI\ecs-cli.exe' https://amazon-ecs-cli.s3.amazonaws.com/ecs-cli-windows-amd64-latest.exe
  • Apply to execute permissions to the binary.

  • Edit the environment variables and add C:\Program Files\Amazon\ECSCLI to the PATH variable field, separated from existing entries by using a semicolon. For example:

      setx path "%path%;C:\Program Files\Amazon\ECSCLI"
    
    • Restart PowerShell so the changes go into effect.

    • Verify that the CLI is working properly.

ecs-cli --version

✍Setting Up ECS CLI:

ECS CLI is a command-line tool that simplifies the process of creating and managing ECS resources.

$ ecs-cli configure --region <region> --access-key <access-key> --secret-key <secret-key> --cluster <cluster-name>

✍Configuring AWS Credentials:

Ensure you have the necessary AWS credentials configured using aws configure the command.

In this demo, we will Create the Cluster using AWS Management Console.

✍Steps for creating the ECS Cluster:

  • Go to the AWS Management Console and Navigate to the ECS Service

  • Click on the Create Cluster

  • Name the Cluster

  • In the Infrastructure select the AWS Fargate this is serverless

  • Now Click on the Crate button.

  • Our Cluster was created successfully.

  • Now we will create one docker image and push it to the ECR(Elastic Container Registry).

  • Dockerfile you will get in my Github repo of 30 Days of AWS Series.

  • Github repo

  • Now We have the Dockerfile now we will build the dockerfile to create the docker image.

  • use this command to build the image.

  •   docker build -t <name tag>:latest .
    

    -

  • Our build is successful now we will push this image to the ECR.

  • use this command to push

  •   docker push <name of your image>
    

    -

  • Now we have our container image on ECR and Now we can use ECS.

  • If you want to understand more about ECR then please check my previous blog where I explained ECR in detail.

  • Now we need a task definition for ECS.

  • Go to the AWS management console and navigate to the ECS Service there is the left panel you will see one option task Definition click on that.

  • Now we will create the task definition.

  • Click on the Create new task definition.

  • Give the task definition name and select launch type as AWS Fargate.

  • Now we have to give the container name and repo URL and port

  • Now click on the Create button.

  • After this when your task definition is active then click on Deploy>run task.

  • Now Click on the Create button.

  • It will take some time to run.

  • After successfully completing this project then delete it because AWS charge you for ECS service.

Thanks for reading this blog.

✍Conclusion

In conclusion, AWS ECS offers a robust and user-friendly platform for deploying and managing containerized applications. We covered the fundamentals of ECS, compared it with its alternatives, discussed its pros and cons, and walked through the installation, configuration, and deployment of a sample application.

Happy Learning:))

Did you find this article valuable?

Support Dev Cloud by becoming a sponsor. Any amount is appreciated!