Skip to content

Latest commit

 

History

History
112 lines (66 loc) · 6.25 KB

Deploy_to_AWS_ECS.md

File metadata and controls

112 lines (66 loc) · 6.25 KB

Hands-on: Deploy to AWS Elastic Container Service (ECS)

In this hands-on lab you will deploy a simple container to Amazon AWS Elastic Container Services (ECS) using GitHub Actions.

  1. Create a Amazon ECR container registry:
    Open the Cloud Shell and log in with your AWS account. Run the following commands and adjust AWS_REGION with your desired region (you can find all regions in the top right corner in AWS). Adjust ECR_REPOSITORYto be unique and replace xyz 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
  2. Fork the repository: Fork this repository (if you haven't done so) by clicking the Fork button at the top right corner.

  3. Create access key: In AWS go to My Security Credentials | Access keys| Create New Access Key:

    001_create_access_key

    Note the Access Key ID and Secret Access Key:

    002_IAM Management Console
  4. Create repository secrets: In your forked repository go to Settings | Secrets and create to new secrets AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY using the values of the previous step.

  5. Modify workflow file: Edit .github/workflows/Deploy-AWS.yml and adjust the values under env:. Use AWS_REGION and ECR_REPOSITORY from step 1. If you are a new user on AWS, just replace xyz 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.

  6. Run the workflow: Manually trigger the workflow.

    003_First-Run

    It is expected that the second job Deploy will fail as you have not jet configured ECS. But Build will work and publish our image to the registry.

    Expand Build, tag, and push image to Amazon ECR and copy the image name:

    004_Imagename
  7. 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 the custom tile.

    005-Amazon ECS

    Enter the 'container name' you set in yaml and the image name you copied in the previous step. Set the port to 80:

    006_Image

    Click Next.

    Select the Application Load Balancer and click Next:

    007_Amazon ECS

    Set the Cluster name to the value from the yaml in step 5.

    008_Cluster

    Click `Next' and create the cluster.

    009_Amazon ECS

    Wait until all resource have been created and click View service:

  8. Copy and save the task run definition: Click on the task definition link:

    010_cluster

    Copy all the content from the JSON tab to your clipboard.

    011_taskdef

    Open the file ch9_release/aws-task-definition.json, edit it, and past the content. Commit the file.

  9. 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:

    012_lb1

    Click the load balancer in the group:

    013_lb2

    In the load balancer you see the DNS name under Description. Copy it:

    014_lb3

    Paste it into a new browser window or tab. You should see the Tailwind Traders website from our container:

    015_running container
  10. Run the workflow again: Manually trigger the workflow again.

    003_First-Run

    This time your workflow runs without error and deploys your latest version of the container.