The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Database, Table } from "@alchemy.run/aws/Timestream"; |
| 3 | import { withQueryEndpoint, withWriteEndpoint } from "@alchemy.run/aws/Timestream/internal"; |
| 4 | import { describe, expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as TSQ from "@distilled.cloud/aws/timestream-query"; |
| 7 | import * as TSW from "@distilled.cloud/aws/timestream-write"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | // Amazon Timestream for LiveAnalytics is closed to new AWS customers; accounts |
| 13 | // that were not already onboarded receive `TimestreamNotOnboarded` (a |
| 14 | // specialized AccessDenied) on every operation, including the endpoint- |
| 15 | // discovery call every request must make first. The ungated probes assert that |
| 16 | // gate is surfaced as a typed error; the full lifecycle is gated behind |
| 17 | // AWS_TEST_TIMESTREAM=1 so an onboarded account can run it unchanged. |
| 18 | describe( |
| 19 | "AWS.Timestream.Database", |
| 20 | { tags: ["provider:aws", "provider:aws:timestream", "live"] }, |
| 21 | () => { |
| 22 | test.provider( |
| 23 | "write DescribeEndpoints reports typed TimestreamNotOnboarded", |
| 24 | (_stack) => |
| 25 | Effect.gen(function* () { |
| 26 | const error = yield* TSW.describeEndpoints({}).pipe(Effect.flip); |
| 27 | expect(error._tag).toBe("TimestreamNotOnboarded"); |
| 28 | }), |
| 29 | { timeout: 60_000 }, |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "query DescribeEndpoints reports typed TimestreamNotOnboarded", |
| 34 | (_stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const error = yield* TSQ.describeEndpoints({}).pipe(Effect.flip); |
| 37 | expect(error._tag).toBe("TimestreamNotOnboarded"); |
| 38 | }), |
| 39 | { timeout: 60_000 }, |
| 40 | ); |
| 41 | |
| 42 | test.provider.skipIf(!process.env.AWS_TEST_TIMESTREAM)( |
| 43 | "create database + table, write + query, then delete", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | const { database, table } = yield* stack.deploy( |
| 47 | Effect.gen(function* () { |
| 48 | const database = yield* Database("Metrics"); |
| 49 | const table = yield* Table("Cpu", { |
| 50 | databaseName: database.databaseName, |
| 51 | retentionProperties: { |
| 52 | memoryStoreRetention: "6 hours", |
| 53 | magneticStoreRetention: "30 days", |
| 54 | }, |
| 55 | }); |
| 56 | return { database, table }; |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | expect(database.databaseArn).toBeDefined(); |
| 61 | expect(table.tableArn).toBeDefined(); |
| 62 | expect(table.tableStatus).toBe("ACTIVE"); |
| 63 | |
| 64 | // Out-of-band verification via distilled through the discovered |
| 65 | // endpoint. |
| 66 | const described = yield* withWriteEndpoint( |
| 67 | TSW.describeTable({ DatabaseName: database.databaseName, TableName: table.tableName }), |
| 68 | ); |
| 69 | expect(described.Table?.TableStatus).toBe("ACTIVE"); |
| 70 | |
| 71 | // Write a point and query it back. |
| 72 | yield* withWriteEndpoint( |
| 73 | TSW.writeRecords({ |
| 74 | DatabaseName: database.databaseName, |
| 75 | TableName: table.tableName, |
| 76 | Records: [ |
| 77 | { |
| 78 | Dimensions: [{ Name: "host", Value: "web-1" }], |
| 79 | MeasureName: "cpu", |
| 80 | MeasureValue: "42.0", |
| 81 | MeasureValueType: "DOUBLE", |
| 82 | Time: `${Date.now()}`, |
| 83 | TimeUnit: "MILLISECONDS", |
| 84 | }, |
| 85 | ], |
| 86 | }), |
| 87 | ); |
| 88 | |
| 89 | const queried = yield* withQueryEndpoint( |
| 90 | TSQ.query({ |
| 91 | QueryString: `SELECT COUNT(*) FROM "${database.databaseName}"."${table.tableName}"`, |
| 92 | }), |
| 93 | ); |
| 94 | expect(queried.Rows.length).toBeGreaterThan(0); |
| 95 | |
| 96 | yield* stack.destroy(); |
| 97 | |
| 98 | const gone = yield* withWriteEndpoint( |
| 99 | TSW.describeDatabase({ DatabaseName: database.databaseName }), |
| 100 | ).pipe( |
| 101 | Effect.map(() => false), |
| 102 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 103 | ); |
| 104 | expect(gone).toBe(true); |
| 105 | }), |
| 106 | { timeout: 300_000 }, |
| 107 | ); |
| 108 | }, |
| 109 | ); |