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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as eventbridge from "@distilled.cloud/aws/eventbridge"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Redacted from "effect/Redacted"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | const CONNECTION_NAME = "alchemy-test-eb-connection"; |
| 12 | const DESTINATION_NAME = "alchemy-test-eb-destination"; |
| 13 | |
| 14 | test.provider( |
| 15 | "connection (Redacted API key) + api destination lifecycle", |
| 16 | (stack) => |
| 17 | Effect.gen(function* () { |
| 18 | yield* stack.destroy(); |
| 19 | |
| 20 | // Create — the API key value is Redacted end-to-end; EventBridge |
| 21 | // stores it in Secrets Manager. |
| 22 | const deployOnce = (options: { description?: string; rateLimit?: number }) => |
| 23 | stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | const connection = yield* AWS.EventBridge.Connection("TestConnection", { |
| 26 | name: CONNECTION_NAME, |
| 27 | description: options.description, |
| 28 | authorizationType: "API_KEY", |
| 29 | authParameters: { |
| 30 | apiKeyAuthParameters: { |
| 31 | apiKeyName: "x-api-key", |
| 32 | apiKeyValue: Redacted.make("alchemy-test-secret-value"), |
| 33 | }, |
| 34 | }, |
| 35 | }); |
| 36 | const destination = yield* AWS.EventBridge.ApiDestination("TestDestination", { |
| 37 | name: DESTINATION_NAME, |
| 38 | connectionArn: connection.connectionArn, |
| 39 | invocationEndpoint: "https://example.com/events", |
| 40 | httpMethod: "POST", |
| 41 | invocationRateLimitPerSecond: options.rateLimit, |
| 42 | }); |
| 43 | return { connection, destination }; |
| 44 | }), |
| 45 | ); |
| 46 | |
| 47 | const { connection, destination } = yield* deployOnce({ rateLimit: 5 }); |
| 48 | |
| 49 | expect(connection.connectionName).toBe(CONNECTION_NAME); |
| 50 | expect(connection.connectionState).toBe("AUTHORIZED"); |
| 51 | expect(connection.secretArn).toBeTruthy(); |
| 52 | expect(destination.apiDestinationName).toBe(DESTINATION_NAME); |
| 53 | expect(destination.apiDestinationState).toBe("ACTIVE"); |
| 54 | |
| 55 | // Out-of-band verify via distilled — the secret never appears in |
| 56 | // attributes or describe output (only its Secrets Manager ARN). |
| 57 | const describedConnection = yield* eventbridge.describeConnection({ |
| 58 | Name: CONNECTION_NAME, |
| 59 | }); |
| 60 | expect(describedConnection.AuthorizationType).toBe("API_KEY"); |
| 61 | expect(describedConnection.SecretArn).toBeTruthy(); |
| 62 | expect(describedConnection.AuthParameters?.ApiKeyAuthParameters?.ApiKeyName).toBe( |
| 63 | "x-api-key", |
| 64 | ); |
| 65 | |
| 66 | const describedDestination = yield* eventbridge.describeApiDestination({ |
| 67 | Name: DESTINATION_NAME, |
| 68 | }); |
| 69 | expect(describedDestination.InvocationEndpoint).toBe("https://example.com/events"); |
| 70 | expect(describedDestination.InvocationRateLimitPerSecond).toBe(5); |
| 71 | |
| 72 | // Update — description and rate limit sync in place (no replace). |
| 73 | const { connection: updatedConnection, destination: updatedDestination } = yield* deployOnce({ |
| 74 | description: "updated connection", |
| 75 | rateLimit: 10, |
| 76 | }); |
| 77 | expect(updatedConnection.connectionArn).toBe(connection.connectionArn); |
| 78 | expect(updatedDestination.apiDestinationArn).toBe(destination.apiDestinationArn); |
| 79 | |
| 80 | const afterUpdate = yield* eventbridge.describeConnection({ |
| 81 | Name: CONNECTION_NAME, |
| 82 | }); |
| 83 | expect(afterUpdate.Description).toBe("updated connection"); |
| 84 | const destinationAfterUpdate = yield* eventbridge.describeApiDestination({ |
| 85 | Name: DESTINATION_NAME, |
| 86 | }); |
| 87 | expect(destinationAfterUpdate.InvocationRateLimitPerSecond).toBe(10); |
| 88 | |
| 89 | yield* stack.destroy(); |
| 90 | |
| 91 | // Typed wait-until-gone — connection deletion is asynchronous |
| 92 | // (DELETING state), so poll until NotFound. |
| 93 | const gone = yield* eventbridge.describeConnection({ Name: CONNECTION_NAME }).pipe( |
| 94 | Effect.map(() => false), |
| 95 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 96 | Effect.repeat({ |
| 97 | schedule: Schedule.spaced("3 seconds"), |
| 98 | until: (isGone): boolean => isGone, |
| 99 | times: 15, |
| 100 | }), |
| 101 | ); |
| 102 | expect(gone).toBe(true); |
| 103 | |
| 104 | const destinationGone = yield* eventbridge |
| 105 | .describeApiDestination({ Name: DESTINATION_NAME }) |
| 106 | .pipe( |
| 107 | Effect.map(() => false), |
| 108 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 109 | ); |
| 110 | expect(destinationGone).toBe(true); |
| 111 | }), |
| 112 | { |
| 113 | tags: ["provider:aws", "provider:aws:eventbridge", "live"], |
| 114 | timeout: 180_000, |
| 115 | }, |
| 116 | ); |