Amazon ECS Lab2
Amazon ECS Lab2
https://medium.com/@raaj.akshar/a-step-by-step-ecs-tutorial-838d60fde8d
Agenda
This post provides a step by step tutorial to get started with ECS, i.e
Elastic Container Service.
You might not want to execute this task on the application server since
it would consume the application server’s resources.
This task of sending SMS or Emails can be easily accomplished on an
ECS setup.
Prerequisites
To complete this tutorial, following prerequisites are expected.
- AWS Account
- AWS CLI setup
- Docker setup
aws --version
$ docker --help
Shell script
Let’s write a shell script which writes “Winter is coming!” to the
standard output.
$ mkdir echo-script
$ cd echo-script
Create a script.sh file.
$ vim script.sh
$ ./script.sh
$ vim Dockerfile
FROM ubuntu:latest
WORKDIR /srv
ADD script.sh /srv
CMD ["/bin/bash", "script.sh"]
With the Dockerfile added, let’s build an image for this application.
Let’s verify that we are able to run a Docker container using this image.
$ docker rm echo-container
ECR repository
For ECS to be able to use the Docker image, the image needs to be
hosted on a registry.
Click on View push commands, this would tell the steps needed to
push the image from your local machine to ECR repository.
Let’s execute these commands to push the image to ECR repository.
Once the above command is executed, you would see message Login
Succeeded.
We can skip step 2 since we have already built the image locally.
As per step 3, let’s tag the local image, this will allow us to push the
image to the ECR repository.
Refresh the repository detail page. You would start seeing an image
with Image tag as latest.
Task definition
ECS creates tasks based on task definition. Task definition are
templates based on which tasks are created.
A task is essentially an instance of a task definition.
Step 1
You would find Essential Container set as Yes. Let Private registry
authentication be toggled off.
We don’t want to map any port of the container with a port on the host.
Hence remove the Port mappings.
You would find a button called + Add more containers. A task
definition can have multiple containers.
We will only have a single container in our task definition, so ignore
this button.
Step 3
Cluster creation
We need a cluster to run an ECS task.
Navigate to Clusters section. You would find it in the Left side
navigation.
You would land on Cluster list page. Navigate to the cluster detail page.
Click on Run new task. You would start seeing the Create form.
You would be navigated back to the Cluster detail page. You would
notice a Tasks launched notification.
Conclusion
We were able to get an application executed without provisioning and
managing any server.
We only touched the tip of the iceberg. ECS is much more capable and
powerful at provisioning, management and orchestration. It has
numerous other use cases where it can shine.