RestApiEventSource
Source:
src/AWS/ApiGateway/RestApiEventSource.ts
Event source connecting a RestApi route to the hosting Lambda
function.
At deploy time the Lambda implementation (Lambda.RestApiEventSource)
materializes the path Resources, the Method with an AWS_PROXY
integration, and the invoke Permission for the route — and registers
each of them as bindings on the API so any Deployment of the same API
is ordered after them. At runtime it dispatches matching REST proxy
events to the handler. Subscribe routes with onRestApiRoute and
provide Lambda.RestApiEventSource on the hosting function.
Handling REST API routes
Section titled “Handling REST API routes”export default MyFunction.make( { main: import.meta.url }, Effect.gen(function* () { const api = yield* ApiGateway.RestApi("Api", { endpointConfiguration: { types: ["REGIONAL"] }, });
yield* ApiGateway.onRestApiRoute( api, { path: "/items", httpMethod: "GET" }, (event) => Effect.succeed({ statusCode: 200, body: JSON.stringify({ items: [] }), }), );
const deployment = yield* ApiGateway.Deployment("Release", { restApi: api, }); yield* ApiGateway.Stage("Prod", { restApi: api, stageName: "prod", deploymentId: deployment.deploymentId, });
return {}; }).pipe(Effect.provide(Lambda.RestApiEventSource)),);