boilerplate-lambda-container/notes/docker.md

53 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

# Build Docker Image
Requirements:
* sam, aws-cli, docker
## Docker Container
Push a docker image to the ECR repository.
```sh
export AWS_REGION=us-west-1
export AWS_PROFILE=playground
aws configure sso --profile $AWS_PROFILE
export REPOSITORY_URI=$(aws ecr describe-repositories --repository-names hello-world --region $AWS_REGION --profile $AWS_PROFILE | jq -r '.repositories[0].repositoryUri')
aws ecr get-login-password --region $AWS_REGION --profile $AWS_PROFILE | docker login --username AWS --password-stdin $REPOSITORY_URI
```
Build the docker image and push it to the ECR repository.
```sh
docker build -t hello-world .
docker tag hello-world:latest $REPOSITORY_URI:latest
docker push $REPOSITORY_URI:latest
```
### Testing
Test the container image locally.
```sh
docker run -p 8000:8000 hello-world:latest
```
Check it in another terminal tab.
```sh
curl http://localhost:8000
docker stop $(docker ps -q)
```
Cleanup the repo.
```sh
aws ecr delete-repository --repository-name hello-world --region $AWS_REGION --profile $AWS_PROFILE --force
```
## Resources
* [deno lambda guide](https://docs.deno.com/runtime/tutorials/aws_lambda/)
* (Deprecated) Deno on AWS Lambda: [Manual lambda packaging guide](https://github.com/denoland/deno-lambda/tree/f735a1a4f0a4a57a348f8af88d6cf30ddc0a5f2e)