7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS SAM の Docker Images 作成

Posted at

なぜやる

Lambda の自動テストのため、Background に実行できるAPI Gatewayが必要

どうやる

AWS SAM の Docker Image 作れば、Background で sam local start-api のコマンドでAPI Gateway 起動できる

どうやった

Dockerfile
FROM python:3.7-alpine

RUN apk add --no-cache --virtual build-deps build-base gcc && \
  pip install aws-sam-cli && \
  apk del build-deps

WORKDIR /var/opt

EXPOSE 3000

ENTRYPOINT ["/usr/local/bin/sam"]
$ docker build -t aws-sam-cli .
Successfully built 281181c0ac11
Successfully tagged aws-sam-cli:latest

どう使う

shell
$ git clone https://github.com/wwalpha/docker-aws-sam-cli.git
$ cd docker-aws-sam-cli
$ docker run -itd --rm \
	-v /var/run/docker.sock:/var/run/docker.sock \
	-v "$(PWD)/example":/var/opt \
	-p "3000:3000" \
	wwalpha/aws-sam-cli local start-api --docker-volume-basedir "$(PWD)/example" --host 0.0.0.0

データベースなど他のネットワークに接続したい場合、最後に --docker-network xxxxx が設定できます。

使ってみる

Shell_OR_PowerShell
$ curl http://localhost:3000
Hello, World!

参考資料

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?