Make sure that SAM CLI is installed.
- Build
sam build
- Testing lambda locally
# We first build and copy dist files into .aws-sam
yarn pre-deploy
# With an example event data - this works
sam local invoke
# Startup API Gateway and Lambda in a container
sam local start-api
# Test with curl
curl http://127.0.0.1:3000/get-users
- Deploy the function
We first need to build the template, compile TypeScript and copy the dist folder, then deploy. We can override any default config in samconfig.toml file.
yarn pre-deploy
sam deploy --s3-bucket test.lambdafunction.bucket --s3-prefix simpleapiproxy
- Clean up the function
aws cloudformation delete-stack --stack-name ts-simple-api-proxy-with-sam
There are two configuration files for SAM in this example
-
template.yaml
-
samconfig.toml
- This file is a project-level configuration file that stores default parameters.
By default SAM CLI pushes the function from build/TsSimpleApiProxyFunction. Therefore, the dist folder has to be copied into it.