Serverless AWS lambda
Config serverless with aws
serverless config credentials --provider aws --key <ACCESS_KEY_AWS> --secret <SECRET_KEY_AWS>
Init project
serverless create --template aws-nodejs --name cake-ordering-system
Define how to trigger lambda in serverless.yml
for example:
functions:
createOrder:
handler: handler.createOrder
# trigger for lambda
events:
# http: stands for APIGateWay
- http:
path: /order
method: post
Hanlder
In handler.js
:
"use strict";
module.exports.createOrder = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({
message: "Create Order",
input: event,
}),
};
};
Deploy
sls deploy
Logs
sls logs -f <FUNCTION_NAME>
## sls logs -f notifyExternalParties
Clean up
sls remove