Skip to content

GetLogEvents

Source: src/AWS/Logs/GetLogEvents.ts

Runtime binding for logs:GetLogEvents.

Bind this operation to a LogGroup inside a function runtime to get a callable that reads log events from a single stream of the group, automatically injecting the log group name.

Read a Stream from the Beginning

const getLogEvents = yield* AWS.Logs.GetLogEvents(logGroup);
const response = yield* getLogEvents({
logStreamName: "my-stream",
startFromHead: true,
});

Wire into a Lambda Function

// Provide the GetLogEventsHttp layer on the Function's init Effect;
// combine with Layer.mergeAll when using several Logs bindings.
export default TailFunction.make(
{ main: import.meta.url, url: true },
Effect.gen(function* () {
const logGroup = yield* AWS.Logs.LogGroup("AppLogs", {});
const getLogEvents = yield* AWS.Logs.GetLogEvents(logGroup);
return {
fetch: Effect.gen(function* () {
const { events } = yield* getLogEvents({
logStreamName: "my-stream",
startFromHead: true,
});
return HttpServerResponse.json({ events });
}),
};
}).pipe(Effect.provide(AWS.Logs.GetLogEventsHttp)),
);