1import * as Lambda from "@/AWS/Lambda";
2import * as SQS from "@/AWS/SQS";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Stream from "effect/Stream";
6import * as HttpServerResponse from "effect/http/HttpServerResponse";
7
8// Minimal host Function for the EventSourceMapping `list()` test: it owns an
9// SQS Queue and subscribes to it via `consumeQueueMessages(queue, ...)`, which
10// (through the Lambda `QueueEventSource` layer + registered
11// `QueueEventSourcePolicy`) creates the `AWS.Lambda.EventSourceMapping`
12// resource and grants the role the SQS read permissions the mapping needs.
13export class EventSourceMappingFunction extends Lambda.Function<EventSourceMappingFunction>()(
14 "EventSourceMappingFunction",
15) {}
16
17export default EventSourceMappingFunction.make(
18 {
19 main: import.meta.url,
20 functionUrl: false,
21 },
22 Effect.gen(function* () {
23 const queue = yield* SQS.Queue("EventSourceMappingQueue");
24
25 yield* SQS.consumeQueueMessages(queue, (stream) =>
26 stream.pipe(Stream.runDrain),
27 );
28
29 return {
30 fetch: Effect.gen(function* () {
31 return HttpServerResponse.text("ok");
32 }).pipe(Effect.orDie),
33 };
34 }).pipe(Effect.provide(Layer.mergeAll(Lambda.QueueEventSource))),
35);