The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as iam from "@distilled.cloud/aws/iam"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import type { AccessKey } from "./AccessKey.ts"; |
| 6 | import { GetAccessKeyLastUsed } from "./GetAccessKeyLastUsed.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Bespoke (resource-bound) IAM HTTP binding: unlike the account-level |
| 10 | * bindings built on `makeIamHttpBinding`, this one binds a canonical |
| 11 | * {@link AccessKey} and injects its `AccessKeyId` into every request. |
| 12 | */ |
| 13 | export const GetAccessKeyLastUsedHttp = Layer.effect( |
| 14 | GetAccessKeyLastUsed, |
| 15 | Effect.gen(function* () { |
| 16 | const bind = yield* AWSBindings.Bind; |
| 17 | const op = yield* AWSBindings.withCredentials(iam.getAccessKeyLastUsed); |
| 18 | |
| 19 | return Effect.fn(function* <K extends AccessKey>(accessKey: K) { |
| 20 | const AccessKeyId = yield* accessKey.accessKeyId; |
| 21 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 22 | yield* bind`AWS.IAM.GetAccessKeyLastUsed(${accessKey})`({ |
| 23 | policyStatements: [ |
| 24 | { |
| 25 | Effect: "Allow", |
| 26 | Action: ["iam:GetAccessKeyLastUsed"], |
| 27 | // The action is evaluated against the owning *user*, whose |
| 28 | // path-qualified ARN is not derivable from the access key. |
| 29 | Resource: ["*"], |
| 30 | }, |
| 31 | ], |
| 32 | }); |
| 33 | } |
| 34 | return Effect.fn(`AWS.IAM.GetAccessKeyLastUsed(${accessKey.LogicalId})`)(function* () { |
| 35 | return yield* op({ AccessKeyId: yield* AccessKeyId }); |
| 36 | }); |
| 37 | }); |
| 38 | }), |
| 39 | ); |