The best way to control Claude Code, Codex and more from any computer or phone

main
ts 71 lines 2.58 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Policy } from "@alchemy.run/aws/IoT";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as iot from "@distilled.cloud/aws/iot";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const assertPolicyGone = (policyName: string) =>
12 iot.getPolicy({ policyName }).pipe(
13 Effect.flatMap(() => Effect.fail(new Error(`policy ${policyName} still exists`))),
14 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
15 Effect.retry({
16 while: (e) => e instanceof Error,
17 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
18 }),
19 );
20
21 describe.sequential(
22 "AWS.IoT.Policy",
23 { tags: ["provider:aws", "provider:aws:iot", "live"] },
24 () => {
25 test.provider(
26 "creates a policy, updates the document to a new default version, and deletes it",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const created = yield* stack.deploy(
32 Effect.gen(function* () {
33 const policy = yield* Policy("DevicePolicy", {
34 policyDocument: {
35 Version: "2012-10-17",
36 Statement: [{ Effect: "Allow", Action: "iot:Connect", Resource: "*" }],
37 },
38 });
39 return { policyName: policy.policyName };
40 }),
41 );
42
43 const observed = yield* iot.getPolicy({ policyName: created.policyName });
44 expect(observed.policyDocument).toContain("iot:Connect");
45 const firstVersion = observed.defaultVersionId;
46
47 // Update the document — creates a new default version.
48 yield* stack.deploy(
49 Effect.gen(function* () {
50 yield* Policy("DevicePolicy", {
51 policyDocument: {
52 Version: "2012-10-17",
53 Statement: [
54 { Effect: "Allow", Action: "iot:Connect", Resource: "*" },
55 { Effect: "Allow", Action: "iot:Publish", Resource: "*" },
56 ],
57 },
58 });
59 }),
60 );
61 const updated = yield* iot.getPolicy({ policyName: created.policyName });
62 expect(updated.policyDocument).toContain("iot:Publish");
63 expect(updated.defaultVersionId).not.toEqual(firstVersion);
64
65 yield* stack.destroy();
66 yield* assertPolicyGone(created.policyName);
67 }),
68 { timeout: 180_000 },
69 );
70 },
71 );