Demonstrates how to use AWS SAM with LocalStack to create a Lambda function and an API Gateway with an authorizer.
- A valid LocalStack for AWS license. Your license provides a
LOCALSTACK_AUTH_TOKENto activate LocalStack. lstkCLI.- Docker
make- AWS CLI, required by
lstk aws. - Serverless Application Model, used via the
lstk samproxy. - NodeJS 18.x
ulid
Setup Serverless Application Model (SAM) on your local machine. We also recommend using NodeJS 14.x alongside a Node Version Manager to manage your NodeJS versions.
Start LocalStack with the LOCALSTACK_AUTH_TOKEN pre-configured:
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
make startOptionally, create a file named .env-local to persist your token (it is ignored by gitignore):
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>Let us first install the local dependencies:
make installTo setup the infrastructure on LocalStack, run:
make deployYou will be prompted to enter a name for the stack. Use the default options for the prompts and fill Y (Yes) for the confirmation prompt. The stack will be created and the output will be printed to the console.
After deploying, you can invoke the Lambda function using the following commands:
make invoke-allow
make invoke-deny
make invoke-unauthorized
make invoke-none