Build Lambda local with SAM CLI
[1]. Requirements
SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
* Node.js - [Install Node.js 12](https://nodejs.org/en/), including the NPM package management tool.* For run locally: Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
[2]. Run lambda local
# Invoking lambda function with event file$ sam local invoke "HelloWorldFunction" -e event.json* Run command API endpoint :$ sam local start-api --parameter-overrides Stage=local$ aws lambda invoke --function-name "HelloWorldFunction" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt
[3]. Deploy cloud (dev)
* Create package and edit template.yaml using AWS S3 location resources.$ sam package --template-file template.yaml --s3-bucket test-lambda-upload --output-template-file deploy-template.yaml* Deploy to AWStest-stack-name` is stack name. Should be changed on every deployment.
$ sam deploy --template-file ./deploy-template.yaml --capabilities CAPABILITY_IAM --parameter-overrides Stage=dev --stack-name test-stack-name
Comments
Post a Comment