Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/devteds/docker-on-aws-apprunner

This source code is for the short course that does a walkthrough of creating a simple website, dockerize as nginx image, create AWS ECR repository, push the image to ECR and finally deploy it to AppRunner along with creating necessary IAM resources.
https://github.com/devteds/docker-on-aws-apprunner

apprunner aws-apprunner devcontainer devops docker nginx

Last synced: about 1 month ago
JSON representation

This source code is for the short course that does a walkthrough of creating a simple website, dockerize as nginx image, create AWS ECR repository, push the image to ECR and finally deploy it to AppRunner along with creating necessary IAM resources.

Awesome Lists containing this project

README

        

# Docker on AWS AppRunner

[Learn how to deploy](https://youtu.be/1BZlUneXLCs) a simple website to AWS App Runner using Docker and NGINX. This project walks you through the steps, from image creation to deployment.

## Announcement: Course on Kubernetes

> If you want to start deploying your containers to Kubernetes, especially on AWS EKS, [check this course on Kubernetes](https://www.devteds.com/kubernetes-course-aws-eks-terraform) that walkthrough creating Kubernetes cluster on AWS EKS using Terraform and deploying multiple related containers applications to Kubernetes and more. https://www.devteds.com/kubernetes-course-aws-eks-terraform

---

[Course video link](https://youtu.be/1BZlUneXLCs)

[![Course Video Link](./doc/docker-on-aws-apprunner.png)](https://youtu.be/1BZlUneXLCs)

Visit https://devteds.com to watch all the videos and courses on DevOps and Cloud courses.

## Terminal Window Log

### Get the code ready

```
git clone
cd docker-on-aws-apprunner
cp .devcontainer/devcontainer.example.json .devcontainer/devcontainer.json
# Edit .devcontainer/devcontainer.json to update .aws path
# Edit aws/apprunner-nginx-service.yml and update ECR image repo:tag
```

## Build & Open in Container Environment (VSCode DevContainer)

If you don't use VS-Code and you may either use the devcontainer cli or other container alternatives or you just use the CLIs installed on your host OS.

And if you're using DevContainer, `DevContainers: ReBuild & ReOpen in Container`

## Docker Build: Build website image

```
cd web
docker build -t nginx-website .
# or
# docker build --platform linux/amd64 -t nginx-website .
```

### ECR Repository & Docker Push

```
aws ecr create-repository --repository-name nginx-ws
docker tag nginx-website .dkr.ecr..amazonaws.com/nginx-ws:v1
aws ecr get-login-password --region | docker login --username AWS --password-stdin .dkr.ecr..amazonaws.com
docker push .dkr.ecr..amazonaws.com/nginx-ws:v1
```

## AWS AppRunner

Got to the root of the project folder.

### Create IAM Role & Policy

```
aws iam create-role --role-name demo-apprunner-role --assume-role-policy-document file://$PWD/aws/trust-policy.json
aws iam create-policy --policy-name demo-apprunner-ecr-policy --policy-document file://$PWD/aws/apprunner-ecr-policy.json
aws iam attach-role-policy --role-name demo-apprunner-role --policy-arn arn:aws:iam::poilcy/demo-apprunner-ecr-policy
```

### Create Nginx Service

Update the aws/apprunner-nginx-service.yml for

- `SourceConfiguration > ImageRepository > ImageIdentifier:` ``, ``
- `SourceConfiguration > AuthenticationConfiguration > AccessRoleArn:` ``

```
aws apprunner create-service --cli-input-yaml file://$PWD/aws/apprunner-nginx-service.yml
```

### Test the Service

```
aws apprunner list-services
```

Use the `ServiceUrl` from the `aws apprunner list-services` response to hit the app on browser and verify.

## All done? Let's clean up

- Delete the App Runner service `aws apprunner delete-service --service-arn `
- Delete the role & policy
- Delete the ECR repository

## Author

**Chandra Shettigar | Devteds**

- Website: https://devteds.com
- LinkedIn: https://www.linkedin.com/in/shettigarc

## Tools & Versions I used

- MacOS, Apple M1 chip
- Docker 24.0.2, build cb74dfc
- Docker Compose version v2.18.1
- VSCode 1.87.2 (Universal)
- aws-cli/2.16.4