Supporting the blog article "AWS Lambda Function URLs with SAM Local and Postman"
Table of Contents
This repo is supporting code for the Medium article "AWS Lambda Function URLs with SAM Local and Postman". In the article, we look specifically at invoking a local Lambda Function via URL using Postman. To simplify the approach we utilize Fastify to quickly set up an API in our Lambda, and include a SAM template to facilitate the local deployment and execution of the function.
This repo contains all the code needed to run the lambda locally and should be sufficient for deploying to AWS.
Feature | Description | |
---|---|---|
โ๏ธ | Architecture | The project leverages AWS Lambda and Fastify to create a serverless web application. |
๐งช | Testing | Jest and ts-jest are used for testing, ensuring code reliability and robustness. Test coverage is minimal for example only. |
๐ฆ | Dependencies | Key dependencies include Fastify, AWS Lambda, Jest, SAM CLI and other related libraries. |
โโโ fastify-lambda-url/
โโโ LICENSE
โโโ README.md
โโโ event.json
โโโ jest.config.js
โโโ package-lock.json
โโโ package.json
โโโ src
โ โโโ app.ts
โ โโโ index.ts
โ โโโ tests
โโโ template.yaml
โโโ tsconfig.json
โโโ webpack.config.js
root
File | Summary |
---|---|
jest.config.js | Configures Jest for TypeScript tests in a Node environment by specifying the TypeScript preset and test file matching patterns. |
event.json | Describes an AWS Lambda event payload for a route related to headers, query parameters, request context, and body data. |
webpack.config.js | The webpack configuration for building the project. |
package.json | Manages dependencies, testing, starting the server, and bundling for production. Dependencies include Fastify, AWS Lambda, and Jest for testing. |
tsconfig.json | Enables strict TypeScript compilation targeting ES2020 and CommonJS modules while excluding test files. Maintains consistent file casing and interop with ES modules, with output to the dist directory. |
template.yaml | Defines SAM template for deployment of the lambda using sam or cfn and creating the Lambda function URL. |
src
File | Summary |
---|---|
index.ts | Enables AWS Lambda integration for Fastify app, routing APIGatewayProxyEvent to app logic via awsLambdaFastify. Centralizes Lambda proxy setup within handler method. |
app.ts | Implements Fastify routes for hello endpoint using GET and POST methods. Registers routes with Fastify instance for a server. |
System Requirements:
- TypeScript
- NPM
- SAM CLI
- Postman or ability to issue curl commands
- Clone the fastify-lambda-url repository:
git clone https://github.com/sawyerit/fastify-lambda-url
- Change to the project directory:
cd fastify-lambda-url
- Install the dependencies:
npm install
Run fastify-lambda-url using the command below:
npm run build
and then
npm run start
Run the test suite using the command below:
npm run test
See CREATING.
This project is protected under the MIT License. For more details, refer to the LICENSE file.