punbots$ sam build && sam deployThe SAM CLI installs dependencies defined in $FUNC_NAME/package.json, creates a deployment package, and saves it in the .aws-sam/build folder.
Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the events folder in this project.
Run functions locally and invoke them with the sam local invoke command.
punbots$ sam build && env DEBUG='monthly:index' sam local invoke "ScoresMonthlyFunction" -e ./events/dydb-update.jsonThe SAM CLI can also emulate your application's API. Use the sam local start-api to run the API locally on port 3000.
punbots$ sam local start-api
punbots$ curl http://localhost:3000/The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The Events property on each function's definition includes the route and method for each path.
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: getlogs are using the debug package. To enable, pass/add an environment variable to the lambda (maybe in the template) with debug = monthly:*,votes:* or whatever subset needed.
To simplify troubleshooting, SAM CLI has a command called sam logs. sam logs lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
NOTE: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
punbots$ sam logs -n HelloWorldFunction --stack-name punbots --tailpunbots$ cd hello-world
hello-world$ npm install
hello-world$ npm run test