Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 2.09 KB

README.md

File metadata and controls

62 lines (44 loc) · 2.09 KB

AWS Serverless Application Model (SAM) with LocalStack Lambda and Authorizer

Demonstrates how to use AWS SAM with LocalStack to create a Lambda function and an API Gateway with an authorizer.

Architecture

Prerequisites

Installing

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 start

Optionally, create a file named .env-local to persist your token (it is ignored by gitignore):

export LOCALSTACK_AUTH_TOKEN=<your-auth-token>

Deploy the application

Let us first install the local dependencies:

make install

To setup the infrastructure on LocalStack, run:

make deploy

This deploys the stack sam-app without prompting. Set STACK_NAME to use another name, for example make deploy STACK_NAME=my-stack. The stack outputs are 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

To check all four cases at once, run:

make test