Help us understand the problem. What is going on with this article?

DockerでローカルのLambda実行環境を用意する。

はじめに

ファイルの中身のみ記載します。

ディレクトリ構造

.
├── docker-compose.yml
├── lambda
    ├── sample
        └── index.js

docker-compose.ymlの内容

version: '3'

services:
  addData:
    container_name: sample-lambda
    image: lambci/lambda:nodejs12.x
    volumes:
      - ./lambda/sample:/var/task
    ports:
      - 9001:9001
    environment:
      AWS_DEFAULT_REGION: XXXXXXXX
      AWS_ACCOUNT_ID: YYYYYYYY
      DOCKER_LAMBDA_WATCH: 1
      DOCKER_LAMBDA_STAY_OPEN: 1
    command: index.handler

index.jsの内容

const aws = require("aws-sdk");

exports.handler = async (event, context) => {
    context.succeed({
        statusCode: 200,
        body      : JSON.stringify('hallo sample!'),
    });
};

いざ実行!

dockerの起動

docker-compose up

レスポンス確認

別タブで実行

curl -d '{}' http://localhost:9001/2015-03-31/functions/sample/invocations

レスポンス

{"statusCode":200,"body":"\"hallo sample!\""}

終わりに

デプロイなんかもDocker使ってできるみたいですね。
時間があれば、そちらも記載したいと思います:relaxed:

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away