t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Lambda/fixtures/event-source-mapping-handler.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

35 lines
1.2 KiB
TypeScript

import * as Lambda from "@/AWS/Lambda";
import * as SQS from "@/AWS/SQS";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
// Minimal host Function for the EventSourceMapping `list()` test: it owns an
// SQS Queue and subscribes to it via `consumeQueueMessages(queue, ...)`, which
// (through the Lambda `QueueEventSource` layer + registered
// `QueueEventSourcePolicy`) creates the `AWS.Lambda.EventSourceMapping`
// resource and grants the role the SQS read permissions the mapping needs.
export class EventSourceMappingFunction extends Lambda.Function<EventSourceMappingFunction>()(
"EventSourceMappingFunction",
) {}
export default EventSourceMappingFunction.make(
{
main: import.meta.url,
functionUrl: false,
},
Effect.gen(function* () {
const queue = yield* SQS.Queue("EventSourceMappingQueue");
yield* SQS.consumeQueueMessages(queue, (stream) =>
stream.pipe(Stream.runDrain),
);
return {
fetch: Effect.gen(function* () {
return HttpServerResponse.text("ok");
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(Layer.mergeAll(Lambda.QueueEventSource))),
);