You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Architect offers a @scheduled construct, allowing to trigger functions regularly. There is no documentation whatsoever about using it in remix and the adapter currently assumes only HTTP API Gateway invocations. In order to make it work, you need to use a custom server and fiddle around.
Make it work using a custom server
This sample below works and enables you to catch another type of event coming to your application.
import{createRequestHandler}from"@remix-run/architect";import*asbuildfrom"@remix-run/dev/server-build";importtype{ServerBuild}from"@remix-run/node";importtype{APIGatewayProxyEventV2,ScheduledEvent}from"aws-lambda";importtype{Handler}from"aws-lambda/handler";consthttpHandler=createRequestHandler({build: buildasunknownasServerBuild,mode: process.env.NODE_ENV,});exportconsthandler: Handler=(event: APIGatewayProxyEventV2|ScheduledEvent,context,callback)=>{if('detail-type'inevent){// Catch scheduled events here and do what you want!console.log(event);callback(null,null);return;}returnhttpHandler(event,context,callback);};
There are still challenges
First, you don't know which of the "scheduled" the invocation was triggered from. The resources property of the event contains the EventBridge schedule ARN but given arc isolates the resources per application, you need to find a "mapping" and as opposed to what's happening with DynamoDB tables or buckets, it's not sent to AWS' Parameter Store.
It is re-using the same server so basically, you have plenty of the application's unnecessary code in the Lambda too.
Does anyone know about a better way of doing it?
Does anyone have an idea about a nice DX that could be provided for such use-cases?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Architect offers a
@scheduled
construct, allowing to trigger functions regularly. There is no documentation whatsoever about using it in remix and the adapter currently assumes only HTTP API Gateway invocations. In order to make it work, you need to use a custom server and fiddle around.Make it work using a custom server
This sample below works and enables you to catch another type of event coming to your application.
# app.arc
server.ts
There are still challenges
resources
property of the event contains the EventBridge schedule ARN but givenarc
isolates the resources per application, you need to find a "mapping" and as opposed to what's happening with DynamoDB tables or buckets, it's not sent to AWS' Parameter Store.Does anyone know about a better way of doing it?
Does anyone have an idea about a nice DX that could be provided for such use-cases?
Beta Was this translation helpful? Give feedback.
All reactions