In this hands-on lab you will deploy a simple container to Amazon AWS Elastic Container Services
(ECS) using GitHub Actions.
-
Create a Amazon ECR container registry:
Open the Cloud Shell and log in with your AWS account. Run the following commands and adjustAWS_REGION
with your desired region (you can find all regions in the top right corner in AWS). AdjustECR_REPOSITORY
to be unique and replacexyz
with your user name.$ AWS_REGION=us-east-2
$ ECR_REPOSITORY=xyz-demo-shop
$ aws ecr create-repository \ --repository-name $ECR_REPOSITORY \ --region $AWS_REGION
-
Fork the repository: Fork this repository (if you haven't done so) by clicking the
Fork
button at the top right corner. -
Create access key: In AWS go to
My Security Credentials
|Access keys
|Create New Access Key
:Note the
Access Key ID
andSecret Access Key
: -
Create repository secrets: In your forked repository go to Settings | Secrets and create to new secrets
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
using the values of the previous step. -
Modify workflow file: Edit .github/workflows/Deploy-AWS.yml and adjust the values under
env:
. UseAWS_REGION
andECR_REPOSITORY
from step 1. If you are a new user on AWS, just replacexyz
with your username. If you already have a cluster running, you can use the name here. The service will be created later.env: AWS_REGION: us-east-2 ECR_REPOSITORY: xyz-demo-shop ECS_SERVICE: xyz-demo-shop-service ECS_CLUSTER: default ECS_TASK_DEFINITION: ch9_release/aws-task-definition.json CONTAINER_NAME: xyz-demo-shop
Commit the changes.
-
Run the workflow: Manually trigger the workflow.
It is expected that the second job
Deploy
will fail as you have not jet configured ECS. ButBuild
will work and publish our image to the registry.Expand
Build, tag, and push image to Amazon ECR
and copy the image name: -
Create cluster and ECS: Open the Getting Started with Amazon Elastic Container Service (Amazon ECS) using Fargate wizard (be aware that this URL contains the region!).
Click
Configure
on thecustom
tile.Enter the 'container name' you set in yaml and the image name you copied in the previous step. Set the port to 80:
Click
Next
.Select the
Application Load Balancer
and clickNext
:Set the
Cluster name
to the value from the yaml in step 5.Click `Next' and create the cluster.
Wait until all resource have been created and click
View service
: -
Copy and save the task run definition: Click on the task definition link:
Copy all the content from the
JSON
tab to your clipboard.Open the file ch9_release/aws-task-definition.json, edit it, and past the content. Commit the file.
-
Check that your container is running: To see that your container is running we have to find the DNS name of the load balancer. Go back to your cluster and open the target group:
Click the load balancer in the group:
In the load balancer you see the DNS name under
Description
. Copy it:Paste it into a new browser window or tab. You should see the Tailwind Traders website from our container:
-
Run the workflow again: Manually trigger the workflow again.
This time your workflow runs without error and deploys your latest version of the container.