npm install -g serverless
serverless config credentials --provider aws --key <ACCESS_KEY_AWS> --secret <SECRET_KEY_AWS>
serverless create --template aws-nodejs --name cake-ordering-system
serverless.yml
for example:
functions:
createOrder:
handler: handler.createOrder
# trigger for lambda
events:
# http: stands for APIGateWay
- http:
path: /order
method: post
In handler.js
:
"use strict";
module.exports.createOrder = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({
message: "Create Order",
input: event,
}),
};
};
sls deploy
[Serverless CLI + AWS] Get started with Serverless and AWS lambda
原文:https://www.cnblogs.com/Answer1215/p/14443931.html