Push and deploy an app on AWS with Container

Create an User

Go to IAM and create a User:

Add those two roles:

Download the secret csv and keep it.

Create an ECR (Repository for images)

This time let´s use aws cli, you can do the same things you do on console with the AWS CLI. For more information on how to configure AWS CLI: https://aws.amazon.com/pt/cli/

Execute aws configure and set the credentials of the IAM user:

aws configureAWS Access Key ID [****************.com]: AKIAAsaWASDEULNQAWS Secret Access Key [None]: jPms2dFasfssdcweYsdsfwq+Default region name [None]: us-east-2Default output format [None]: json

Command to create the repository:

aws ecr create-repository –repository-name rest-with-spring-boot

List the repository and get the URI value:

aws ecr describe-repositories

Build the image:

docker-compose build –t rest-with-spring-boot

Now, we can check the commands to push in console, go to ECR and “View push commands”:

Execute the steps 1, 3 and 4. Because we already built the application. Example:

aws ecr get-login-password –region us-east-2 | docker login –username AWS –password-stdi 9999999999.dkr.ecr.us-east-2.amazonaws.com

docker tag project:latest 9999999.dkr.ecr.us-east-2.amazonaws.com/project:latest

docker push 999999.dkr.ecr.us-east-2.amazonaws.com/project:latest

Now, that we have the image in our repository:

Create ECS Cluster

Next

Create a Key-pair if you don´t have it yet.

Let´s fill out the Networking session, and edit the security group

Click to edit the rules, for tests purposes we will allow everything like below:

Create cluster

Click on View Cluster:

After a few minutes, we have an instance running inside the cluster:

Creating the task

A Task is the same thing as a Pod in Kubernetes, it can hold one or more containers. Usually a task contains only one container.


Let’s go back to ECS:

Set a name:

Specify the memory and CPU:

Click on “Add Container”

you can check the image with the command “Docker images”, and then set it to the image field:

You can put 80 in the first field if you want.

And then create the task:

Creating the service

Now, we will create a Service, to manage the scaling the application. Select the task and go to “Create Service”.

Go Next until Create Service button.

Service created:

 Now you can access the app with the address of the EC2 instance:

Push and deploy an app on AWS with Container
Tagged on:                     

Leave a Reply

Your email address will not be published. Required fields are marked *