| 1 | // Package awsjob will hold the AWS Lambda MicroVMs adapter for the isolated |
| 2 | // job runner. Before any adapter code exists, this comment records the API |
| 3 | // facts the adapter relies on, each with its source, as read on 2026-11-22. |
| 4 | // "Not documented" marks a gap that Task 17's live check must close. Nothing |
| 5 | // here is a guess. |
| 6 | // |
| 7 | // SDK. aws-sdk-go-v2 has a package for the service: |
| 8 | // github.com/aws/aws-sdk-go-v2/service/lambdamicrovms. The newest version is |
| 9 | // v1.13.0 (2026-11-20, from go list -m -versions), which requires |
| 10 | // github.com/aws/aws-sdk-go-v2 v1.48.0 and github.com/aws/smithy-go v1.28.9. |
| 11 | // Use it rather than hand-signed SigV4 calls. The API version is 2025-09-09 |
| 12 | // and the SigV4 signing name is "lambda" (endpoints.go in the module). The |
| 13 | // SDK fills ClientToken with a random UUID when it is nil, so the adapter must |
| 14 | // always set it. Source: |
| 15 | // https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/lambdamicrovms |
| 16 | // |
| 17 | // Operations. The runner needs six: RunMicrovm (POST /2025-09-09/microvms), |
| 18 | // GetMicrovm (GET /2025-09-09/microvms/{id}), SuspendMicrovm (POST |
| 19 | // .../microvms/{id}/suspend), ResumeMicrovm (POST .../microvms/{id}/resume), |
| 20 | // TerminateMicrovm (DELETE .../microvms/{id}) and ListMicrovms (GET |
| 21 | // /2025-09-09/microvms). The image operations (CreateMicrovmImage, |
| 22 | // UpdateMicrovmImage, GetMicrovmImageVersion and others) belong to the image |
| 23 | // pipeline. Source: |
| 24 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_Operations.html |
| 25 | // |
| 26 | // Run request. RunMicrovm takes imageIdentifier (required), imageVersion |
| 27 | // (defaults to the latest active version), clientToken, |
| 28 | // ingressNetworkConnectors and egressNetworkConnectors (up to 10 ARNs each), |
| 29 | // executionRoleArn (optional), idlePolicy (optional), |
| 30 | // maximumDurationInSeconds, runHookPayload, kmsKeyIdentifier and logging. It |
| 31 | // has no tags, memory, architecture or capabilities field. Sources: |
| 32 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_RunMicrovm.html |
| 33 | // and https://docs.aws.amazon.com/lambda/latest/dg/microvms-launching.html |
| 34 | // |
| 35 | // Image settings. additionalOsCapabilities (the only value is "ALL"), the CPU |
| 36 | // architecture (cpuConfigurations: ARM_64 or X86_64, ARM_64 when omitted, |
| 37 | // X86_64 from base image version 3) and the baseline memory (resources: |
| 38 | // minimumMemoryInMiB; vCPU follows memory at 2 GB per vCPU) are set on |
| 39 | // CreateMicrovmImage or UpdateMicrovmImage, and every update builds a new image |
| 40 | // version. One image version therefore has one size, so Small and Large need |
| 41 | // separate image versions and the run request picks one. Sources: |
| 42 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_CreateMicrovmImage.html |
| 43 | // and https://docs.aws.amazon.com/lambda/latest/dg/microvms-images.html |
| 44 | // |
| 45 | // Connectors. Egress is the ARN of a VPC_EGRESS connector in |
| 46 | // egressNetworkConnectors; it must be ACTIVE, and an unqualified ARN resolves |
| 47 | // to the connector's latest version. NO_INGRESS is a Lambda-provided ingress |
| 48 | // connector, and lifecycle hooks still work with it. The guide prints the |
| 49 | // managed ingress ARNs for HTTP_INGRESS and SHELL_INGRESS in the form |
| 50 | // arn:aws:lambda:REGION:aws:network-connector:aws-network-connector:NAME; the |
| 51 | // NO_INGRESS ARN itself is not printed. Source: |
| 52 | // https://docs.aws.amazon.com/lambda/latest/dg/microvms-networking.html |
| 53 | // |
| 54 | // Maximum duration. maximumDurationInSeconds goes on the run request, from 1 |
| 55 | // to 28,800, and counts running and suspended time. When it passes, the VM |
| 56 | // moves through TERMINATING to TERMINATED. The default when it is omitted is |
| 57 | // Not documented (the spike saw 8 hours). Sources: the RunMicrovm page above |
| 58 | // and https://docs.aws.amazon.com/lambda/latest/dg/microvms-how-it-works.html |
| 59 | // |
| 60 | // Idle policy and role. Both are optional on the run request. The guide says |
| 61 | // "When enabled, the idle policy controls automatic suspension"; idle time is |
| 62 | // measured by inbound traffic through the endpoint only. Sources: |
| 63 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_IdlePolicy.html |
| 64 | // and the launching page above. |
| 65 | // |
| 66 | // Client token. clientToken is optional, case-sensitive and 1 to 128 |
| 67 | // characters, "to ensure the idempotency of the request". How long a token is |
| 68 | // remembered, what a replay returns after the VM has terminated, and the error |
| 69 | // for a token replayed with a different request are Not documented. AWS |
| 70 | // documents replay behaviour only for CreateMicrovmImage, where a replay of a |
| 71 | // successful request returns the same response. Task 17 must establish: the |
| 72 | // same token and body return the same microvmId; which error a changed body |
| 73 | // gives (ConflictException 409 and ValidationException 400 are the |
| 74 | // candidates); and the window. Source: the RunMicrovm page above. |
| 75 | // |
| 76 | // States. PENDING, RUNNING, SUSPENDING, SUSPENDED, TERMINATING, TERMINATED. |
| 77 | // TERMINATED is terminal. There is no FAILED state: a /run hook that fails or |
| 78 | // times out can move a VM from PENDING straight to TERMINATING, and stateReason |
| 79 | // explains an unexpected termination. A VM stays SUSPENDED while its /resume |
| 80 | // hook runs. The state from GetMicrovm is eventually consistent. The SDK warns |
| 81 | // that the enum can grow, so an unfamiliar value must map to unknown. Sources: |
| 82 | // the how-it-works page above, |
| 83 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_GetMicrovm.html |
| 84 | // and https://docs.aws.amazon.com/lambda/latest/dg/microvms-best-practices.html |
| 85 | // |
| 86 | // Start time and server time. GetMicrovm and RunMicrovm return startedAt, |
| 87 | // "the timestamp when the MicroVM first started", and terminatedAt. |
| 88 | // ListMicrovms items always carry startedAt. Whether startedAt is set while |
| 89 | // PENDING, and whether it marks the run call or the end of the /run hook, is |
| 90 | // Not documented. A Date header on responses is Not documented for this |
| 91 | // service; the SDK records it when present, read with GetServerTime from |
| 92 | // github.com/aws/aws-sdk-go-v2/aws/middleware on the output's ResultMetadata. |
| 93 | // Task 17 must confirm both. Sources: the GetMicrovm page above and |
| 94 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_MicrovmItem.html |
| 95 | // |
| 96 | // Resume. ResumeMicrovm "resumes a suspended MicroVM" and "The MicroVM must be |
| 97 | // in SUSPENDED state"; its errors include ConflictException (409), "a conflict |
| 98 | // with the current state of the resource". What it returns for a RUNNING VM |
| 99 | // is Not documented, and ConflictException is the likely answer. That is a |
| 100 | // typed error, so the adapter can treat it as a no-op once GetMicrovm shows |
| 101 | // RUNNING. Task 17 must check the error for a RUNNING VM and for a VM still |
| 102 | // SUSPENDED while its /resume hook runs. SuspendMicrovm likewise lists |
| 103 | // ConflictException, and its result on a SUSPENDED VM is Not documented. |
| 104 | // Sources: |
| 105 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_ResumeMicrovm.html |
| 106 | // and https://docs.aws.amazon.com/lambda/latest/microvm-api/API_SuspendMicrovm.html |
| 107 | // |
| 108 | // Terminate. TerminateMicrovm "is idempotent; terminating a MicroVM that has |
| 109 | // already been terminated succeeds without error". It can still return |
| 110 | // ResourceNotFoundException (404); how long a terminated VM stays visible is |
| 111 | // Not documented. Source: |
| 112 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_TerminateMicrovm.html |
| 113 | // |
| 114 | // List. ListMicrovms pages with maxResults (1 to 50) and nextToken, which is |
| 115 | // null on the last page, and can filter by image and image version. Items |
| 116 | // carry microvmId, imageArn, imageVersion, startedAt and state, with no tags |
| 117 | // or client token. Source: |
| 118 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_ListMicrovms.html |
| 119 | // Neither the API reference nor the SDK (lambdamicrovms v1.13.0) gives a |
| 120 | // syntax for microvmId, so the adapter accepts only what |
| 121 | // isolatedjob.Ref.Valid does, 1 to 128 letters, digits and '-' (ruling |
| 122 | // R36), from RunMicrovm, GetMicrovm and every ListMicrovms item, and |
| 123 | // refuses anything else with fixed text. |
| 124 | // The SDK names the image filter ImageIdentifier. |
| 125 | // Runner.List sends it once per configured image ARN and also drops any item |
| 126 | // whose imageArn differs (ruling R32), as an account may hold other |
| 127 | // people's VMs, which the reaper must never take for orphans. That the |
| 128 | // filter matches the ARN RunMicrovm was given, and that imageArn echoes it |
| 129 | // exactly, is not documented; the live contract's List check (Task 17) |
| 130 | // shows it. |
| 131 | // |
| 132 | // Errors. AccessDeniedException 403, ConflictException 409, |
| 133 | // InsufficientCapacityException 500 (run only), InternalServerException 500 |
| 134 | // with retryAfterSeconds, ResourceNotFoundException 404, |
| 135 | // ServiceQuotaExceededException 402 (run only), ThrottlingException 429 and |
| 136 | // ValidationException 400. Sources: the operation pages above. |
| 137 | // |
| 138 | // Hooks, for slice 1b. Lambda sends an HTTP POST to the application inside |
| 139 | // the VM at /aws/lambda-microvms/runtime/v1/run, /resume, /suspend and |
| 140 | // /terminate, on the port set in the image's hooks.port. Each hook is ENABLED |
| 141 | // or DISABLED on the image, with a timeout of 1 to 60 seconds. The VM learns |
| 142 | // its ID from the /run body, JSON {"microvmId": ..., "runHookPayload": ...}. |
| 143 | // The VM takes traffic only after /run returns 200. Sources: the launching |
| 144 | // page above and |
| 145 | // https://docs.aws.amazon.com/lambda/latest/microvm-api/API_MicrovmHooks.html |
| 146 | // |
| 147 | // Payload limit. runHookPayload is a string. The API reference gives a maximum |
| 148 | // length of 4096; the developer guide says "max 16 KB". Until Task 17 |
| 149 | // measures it, use 4096 as the limit. Whether the length counts bytes or |
| 150 | // characters is Not documented, so keep the payload ASCII. Sources: the |
| 151 | // RunMicrovm and launching pages above. |
| 152 | package awsjob |
| 153 | |