Files
triggerdotdev--trigger.dev/apps/proxy/README.md
T
Matt Aitken 2b48e6d04b Feature: sendEvent can use an AWS SQS queue to increase reliability and throughput (#729)
* Initial commit (by create-cloudflare CLI)

* Changed the prettier rules

* Started writing Readme and got dev working

* Validate the request, parse the event and respond with the correct format

* Use ulidx instead of ulid in core

* Removed some boilerplate and use new function for sendEvent

* Removed old ulid package

* When handling a webhook, it’s not an error if the HTTP endpoint environment isn’t found

* If the env vars aren’t set, log the request and pass it through

* Pass requests through. Setup the env vars

* Flipped the API key detection because we can enforce that it’s the shape of a private API key

* Progress with sendEvent proxy

* Events are being put on the SQS queue

* The SQS event queue is working

* Make sure there’s a timestamp before enqueuing the evnet

* Log the sqs_event, not API key

* Added a bit more detail to the readme

* Improved the Cloudflare logs

* We don’t need the global.window hack for AWS, just globalThis

* Removed commented out wrangler.toml values

* Reworked the proxy to make it easier to add more endpoints

* Use json utility to send Responses

* Start work on proxying bulk events
2023-11-13 15:08:01 +00:00

1.5 KiB

Trigger.dev proxy

This is an optional module that can be used to proxy and queue requests to the Trigger.dev API.

Why?

The Trigger.dev API is designed to be fast and reliable. However, if you have a lot of traffic, you may want to use this proxy to queue requests to the API. It intercepts some requests to the API and adds them to an AWS SQS queue, then the webapp can be setup to process the queue.

Current features

  • Intercepts sendEvent requests and adds them to an AWS SQS queue. The webapp then reads from the queue and creates the events.

Setup

1. Create an AWS SQS queue

In AWS you should create a new AWS SQS queue with appropriate security settings. You will need the queue URL for the next step.

Environment variables

Cloudflare secrets

Locally you should copy the .dev.var.example file to .dev.var and fill in the values.

When deploying you should use wrangler (the Cloudflare CLI tool) to set secrets.

wrangler secret put REWRITE_HOSTNAME
wrangler secret put AWS_SQS_ACCESS_KEY_ID
wrangler secret put AWS_SQS_SECRET_ACCESS_KEY
wrangler secret put AWS_SQS_QUEUE_URL
wrangler secret put AWS_SQS_REGION

Webapp

These env vars also need setting in the webapp, however you normally would do that.

AWS_SQS_REGION
AWS_SQS_ACCESS_KEY_ID
AWS_SQS_SECRET_ACCESS_KEY
AWS_SQS_QUEUE_URL
AWS_SQS_BATCH_SIZE

Development

Set the environment variables as described above.

  1. pnpm install
  2. pnpm run dev --filter proxy