Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript
🚀 Using top-level await in AWS Lambda with TypeScript, esbuild and Serverless Framework
https://github.com/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript
aws aws-lambda aws-lambda-node esbuild esm esmodules serverless serverless-esbuild serverless-examples serverless-framework typescript
Last synced: 10 days ago
JSON representation
🚀 Using top-level await in AWS Lambda with TypeScript, esbuild and Serverless Framework
- Host: GitHub
- URL: https://github.com/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript
- Owner: oieduardorabelo
- Created: 2022-08-10T09:07:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-14T02:35:24.000Z (over 1 year ago)
- Last Synced: 2024-04-14T19:10:12.008Z (7 months ago)
- Topics: aws, aws-lambda, aws-lambda-node, esbuild, esm, esmodules, serverless, serverless-esbuild, serverless-examples, serverless-framework, typescript
- Language: TypeScript
- Homepage:
- Size: 252 KB
- Stars: 24
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🚀 Top-level await in AWS Lamba with TypeScript
### Articles
- https://dev.to/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript-1bf0
- https://medium.com/@oieduardorabelo/top-level-await-in-aws-lamba-with-typescript-aeba95b5abc1
- https://oieduardorabelo.hashnode.dev/top-level-await-in-aws-lamba-with-typescript### Summary
This repository demonstrates [Node.js ES modules and top-level await in AWS Lambda](https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/) while developing your code in TypeScript.
### How does that work?
We use [serverless-esbuild](https://github.com/floydspace/serverless-esbuild) to transpile our TypeScript code to JavaScript.
The secret sauce is to configure esbuild to output Node.js ES modules files with `.mjs` extension with the following esbuild options:
```yaml
format: "esm"
outputFileExtension: ".mjs"
platform: "node"
target: "esnext"
```With that in place, you can have a fully typed AWS Lambda code in TypeScript and take advantage of executing `await` outside the handler function, improving the response time for the service consumers.
As [Dan Fox](https://twitter.com/danfox) (Principal Specialist Solutions Architect Serverless) explained in [his article](https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/), we can see around ~45% performance improvements:
![https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/](./docs//await3-1024x400.png)
## 📸 In The Media
- This example was highlighted in the [Off-by-none: Issue #198](https://offbynone.io/issues/198/) newsletter