Run zeit/micro based app on top of AWS Lambda and Amazon API Gateway using aws-serverless-express
SEE: example
const { serve, proxy, withEventContext } = require('micro-lambda')
const micro = require('micro')
// Handle HTTP Request with micro.
const server = serve(micro(withEventContext(async (req, res) => {
if (req.method === 'POST') {
return micro.json(req)
}
return { hoge: 'fuga' }
})))
exports.handler = (event, context, cb) => {
context.callbackWaitsForEmptyEventLoop = false
proxy(server, event, context, cb)
}
# Install dependencies
npm i
# Copy dependencies to child.
cp -r ./node_modules ./functions/example
# Start dev server
npm run dev
# Simulate GET request
cat ./functions/example/__tests__/events/api-gw.json | docker run --rm -v "$PWD":/var/task -i -e DOCKER_LAMBDA_USE_STDIN=1 lambci/lambda:nodejs8.10 functions/example/index.handler
# Simulate POST request
cat ./functions/example/__tests__/events/api-gw-post.json | docker run --rm -v "$PWD":/var/task -i -e DOCKER_LAMBDA_USE_STDIN=1 lambci/lambda:nodejs8.10 functions/example/index.handler
You must setup example
as your AWS Profile(at ~/.aws/credentials && ~/.aws/config).
# Init project.json
apex --profile example init
# Initialize infra(API Gateway)
apex --profile example infra init
# Dry run for see changes.
apex --profile example deploy -D
# Do deploy lambda.
apex --profile example deploy
# Dry run for see changes.
apex --profile example infra plan
apex --profile example infra apply
# Destroy infrastructure.
apex --profile example infra destroy
# Delete lambda
apex --profile example delete
Thanks to original authors of aws-serverless-express package.
MIT License
SEE: LICENSE