https://github.com/danwakeem/funky-async-extension
A Lambda Layer that allows you to execute code after a response has been sent to API Gateway
https://github.com/danwakeem/funky-async-extension
api-gateway async-api aws-lambda lambda serverless
Last synced: 8 months ago
JSON representation
A Lambda Layer that allows you to execute code after a response has been sent to API Gateway
- Host: GitHub
- URL: https://github.com/danwakeem/funky-async-extension
- Owner: Danwakeem
- Created: 2022-10-10T17:23:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-26T20:31:01.000Z (over 3 years ago)
- Last Synced: 2025-02-21T09:46:33.133Z (about 1 year ago)
- Topics: api-gateway, async-api, aws-lambda, lambda, serverless
- Language: JavaScript
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Async HTTP API Lambda Layer
This is a lambda layer package that allows you to return data from your http API before your `ASYNC_HANDLER` has finished executing.
This allows you to perform fire and forget http APIs similar to the old `X-Amz-Invocation-Type: Event` that is [enabled on v1 APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html).
## How to use
This repository is basically an example repo showing how to deploy and integrate with this async handler.
Each function in the `serverless.yml` file presents a different way to interact with the layer.
* `longRunning` - This function demonstrates an ASYNC handler that runs way after a typical HTTP API would be required to return a response. It is also using the built in layer `proxy` handler that will take care of passing the `event` and `context` object to the async handler.
* `customResponse` - This function demonstrates an async handler that uses the built in layer `proxy` handler and customizes the response message.
* `customHandler` - This function demonstrates a custom handler paired with an `ASYNC_HANDLER`. This also demonstrates how to use the `sendArgs` method exposed by our layer.
## Layer details
This layer includes an external extension that is monitoring for an http event from the internal lambda function that forwards the event and context information. It also includes a lambda handler you can use to send quick responses back to API gateway as well as a `sendArgs` method that allows you use a custom handler.
Once the event and context information is received the extension will then execute the `ASYNC_HANDLER` function supplied in our environment variables.
## Environment variables
| Name | Description | Required (Y/N) | Default |
|--|--|--|--|
| `ASYNC_HANDLER` | This is the path to your async handler. This is similar to the normal `handler` property in the function description in the `serverless.yml` file. | `Y` | N/A |
| `CUSTOM_RES` | If you want to use the built-in `proxy` handler but you would like to customize the http response you can do that via this variable. (Example on `customResponse` function 😉) | `N` | N/A |