Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luismeyer/tlfc
Ensure typesafe calls to AWS Lambda functions
https://github.com/luismeyer/tlfc
Last synced: 22 days ago
JSON representation
Ensure typesafe calls to AWS Lambda functions
- Host: GitHub
- URL: https://github.com/luismeyer/tlfc
- Owner: luismeyer
- Created: 2023-07-08T20:43:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-27T13:46:58.000Z (about 1 year ago)
- Last Synced: 2024-10-04T18:41:45.401Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://tlfc-docs.vercel.app/
- Size: 3.24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# @tlfc
Write typesafe AWS lambda functions with:
- ⚙️ minimal configuration effort
- 🏗️ local dev environment
- 🚀 quick deployments
- 🔒 request and response validation
- ⭐️ aws-sdk or fetch for either Browser or Node.js clients
- 😷 typesafe client and server interface## How it works
### A working vite example can be found in the [example app package](./apps/vite/readme.md) or [deployed here](https://tlfc-example.vercel.app/).
### Simple lambda definition and implementation
```ts
import { z } from "zod";import { createLambda } from "@tlfc/server";
export default createLambda(
{
requestSchema: z.object({ name: z.string() }),
responseSchema: z.object({ message: z.string() }),
functionName: "messageHandler",
},
async (event) => {
const message = calculateMessage(event.name);
return { message };
}
);
```### Usage of the lambda in vite client
```ts
import { configure } from "@tlfc/client";import messageLambda from "../server/message-lambda";
configure(import.meta.env.VITE_TLFC_API_PATH);
async function handleClick() {
const response = await messageLambda.call({ name: "Foo" });
title.innerText = response.message;
}
```Under the hood the `@tlfc/vite` plugin transforms the `@tlfc/server` import to a `@tlfc/client` import. Also it strips the lambda implementation and environment Variables from the client bundle.
The `@tlfc/client` package uses the fetch api to call the lambda at a specific endpoint. For local development the endpoint is automatically resolved. For production the `VITE_TLFC_API_PATH` needs to be set to the URL that the `@tlfc/tools` deployment creates.
If the `@tlfc/client` is used outside the browser it will automatically switch to the `aws-sdk` to call the lambda.