@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 03:37 UTC

main
ts 84 lines 2.44 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as Alchemy from "alchemy";
3 import * as Output from "alchemy/Output";
4 import * as Effect from "effect/Effect";
5 import * as Layer from "effect/Layer";
6 import JobFunction from "./src/JobFunction.ts";
7
8 const aws = AWS.providers();
9 const dashboardRegion = process.env.AWS_REGION ?? "us-west-2";
10
11 export default Alchemy.Stack(
12 "JobLambdaHttpApi",
13 {
14 providers: Layer.mergeAll(
15 // Fully configured cloud provider Layers go here:
16 aws,
17 ),
18 state: Alchemy.localState(),
19 },
20 Effect.gen(function* () {
21 const func = yield* JobFunction;
22 const dashboard = yield* AWS.CloudWatch.Dashboard("JobDashboard", {
23 DashboardBody: func.functionName.pipe(
24 Output.map((functionName) => ({
25 widgets: [
26 {
27 type: "metric",
28 x: 0,
29 y: 0,
30 width: 12,
31 height: 6,
32 properties: {
33 title: "Lambda Invocations and Errors",
34 region: dashboardRegion,
35 stat: "Sum",
36 period: 300,
37 metrics: [
38 ["AWS/Lambda", "Invocations", "FunctionName", functionName],
39 ["AWS/Lambda", "Errors", "FunctionName", functionName],
40 ],
41 },
42 },
43 {
44 type: "metric",
45 x: 12,
46 y: 0,
47 width: 12,
48 height: 6,
49 properties: {
50 title: "Lambda Duration",
51 region: dashboardRegion,
52 stat: "Average",
53 period: 300,
54 metrics: [["AWS/Lambda", "Duration", "FunctionName", functionName]],
55 },
56 },
57 ],
58 })),
59 ),
60 });
61 const alarm = yield* AWS.CloudWatch.Alarm("JobFunctionErrorsAlarm", {
62 AlarmDescription: "Alerts when the example Lambda function reports errors.",
63 MetricName: "Errors",
64 Namespace: "AWS/Lambda",
65 Statistic: "Sum",
66 Period: 300,
67 EvaluationPeriods: 1,
68 Threshold: 1,
69 ComparisonOperator: "GreaterThanOrEqualToThreshold",
70 TreatMissingData: "notBreaching",
71 Dimensions: [
72 {
73 Name: "FunctionName",
74 Value: func.functionName,
75 },
76 ],
77 });
78 return {
79 url: Output.interpolate`${func.functionUrl}?jobId=foo`,
80 dashboardName: dashboard.dashboardName,
81 alarmName: alarm.alarmName,
82 };
83 }),
84 );