# install python packagescd sam-app/
pipenv install
pipenv install --dev
pipenv shell
python --version # make sure you see Python 3.7.2 or later# if you want to initialize# sam init --name new-app --location sam-app --runtime python3.7# cd new-app# pipenv --python 3.7# pipenv install -r src/requirements.txt# pipenv install --dev -r src/requirements_dev.txt# note: template.yaml default is python3.6
Test
cd sam-app/
pipenv shell
# run unit test
python -m pytest tests/ -v
Build and Run Locally
cd sam-app/
# the build command create files in# .aws-sam/build/HelloWorldFunction/
sam build --use-container --region ap-northeast-1
# run lambda
sam local invoke HelloWorldFunction --event event.json
Deploy Terraform Module
cd example
# deploy sample code
terraform plan
terraform apply
Note: how to generate event.json
# to use Constant (JSON text)# "{\"event_input\":\"something\"}"# to generate cloudwatch schedule matched event
sam local generate-event cloudwatch scheduled-event
# the SAM init default event.json is generated by the below
sam local generate-event apigateway aws-proxy