1import type * as Logs from "@distilled.cloud/aws/cloudwatch-logs";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { LogGroup } from "./LogGroup.ts";
5
6export interface GetLogEventsRequest extends Omit<
7 Logs.GetLogEventsRequest,
8 "logGroupName" | "logGroupIdentifier"
9> {}
10
11/**
12 * Runtime binding for `logs:GetLogEvents`.
13 *
14 * Bind this operation to a `LogGroup` inside a function runtime to get a
15 * callable that reads log events from a single stream of the group,
16 * automatically injecting the log group name.
17 * ### Reading Logs
18 * **Example:** Read a Stream from the Beginning
19 * ```typescript
20 * const getLogEvents = yield* AWS.Logs.GetLogEvents(logGroup);
21 *
22 * const response = yield* getLogEvents({
23 * logStreamName: "my-stream",
24 * startFromHead: true,
25 * });
26 * ```
27 *
28 * **Example:** Wire into a Lambda Function
29 * ```typescript
30 * // Provide the GetLogEventsHttp layer on the Function's init Effect;
31 * // combine with Layer.mergeAll when using several Logs bindings.
32 * export default TailFunction.make(
33 * { main: import.meta.url, functionUrl: true },
34 * Effect.gen(function* () {
35 * const logGroup = yield* AWS.Logs.LogGroup("AppLogs", {});
36 * const getLogEvents = yield* AWS.Logs.GetLogEvents(logGroup);
37 * return {
38 * fetch: Effect.gen(function* () {
39 * const { events } = yield* getLogEvents({
40 * logStreamName: "my-stream",
41 * startFromHead: true,
42 * });
43 * return HttpServerResponse.json({ events });
44 * }),
45 * };
46 * }).pipe(Effect.provide(AWS.Logs.GetLogEventsHttp)),
47 * );
48 * ```
49 *
50 * @binding
51 */
52export interface GetLogEvents extends Binding.Service<
53 GetLogEvents,
54 "AWS.Logs.GetLogEvents",
55 <G extends LogGroup>(
56 logGroup: G,
57 ) => Effect.Effect<
58 (
59 request: GetLogEventsRequest,
60 ) => Effect.Effect<Logs.GetLogEventsResponse, Logs.GetLogEventsError>
61 >
62> {}
63export const GetLogEvents = Binding.Service<GetLogEvents>(
64 "AWS.Logs.GetLogEvents",
65);