The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import type { Output } from "alchemy/Output"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import Api from "./ApiLambda.ts"; |
| 6 | |
| 7 | const widget = (name: Output<string>) => ({ |
| 8 | type: "metric" as const, |
| 9 | x: 0, |
| 10 | y: 0, |
| 11 | width: 12, |
| 12 | height: 6, |
| 13 | properties: { |
| 14 | title: "Errors", |
| 15 | metrics: [["AWS/Lambda", "Errors", "FunctionName", name]], |
| 16 | stat: "Sum", |
| 17 | period: 60, |
| 18 | }, |
| 19 | }); |
| 20 | |
| 21 | // #region show |
| 22 | export const ObservabilityLive = Layer.unwrap( |
| 23 | Effect.gen(function* () { |
| 24 | const api = yield* Api; |
| 25 | |
| 26 | yield* AWS.CloudWatch.Dashboard("Chat", { |
| 27 | DashboardBody: { widgets: [widget(api.functionName)] }, |
| 28 | }); |
| 29 | yield* AWS.CloudWatch.Alarm("Errors", { |
| 30 | Namespace: "AWS/Lambda", |
| 31 | MetricName: "Errors", |
| 32 | Dimensions: [{ Name: "FunctionName", Value: api.functionName }], |
| 33 | Statistic: "Sum", |
| 34 | Period: 300, |
| 35 | EvaluationPeriods: 1, |
| 36 | Threshold: 10, |
| 37 | ComparisonOperator: "GreaterThanThreshold", |
| 38 | }); |
| 39 | |
| 40 | // Lambda already ships its logs and metrics to CloudWatch. |
| 41 | return Layer.empty; |
| 42 | }), |
| 43 | ); |
| 44 | // #endregion show |