AgentCore Runtime V2
The inference-api runs in an AgentCore Runtime. AWS offers two platform versions of that Runtime. V1 is the default and what every deployment runs unless it opts in. V2 starts sessions from a snapshot of an already-booted container (about 2 s cold start regardless of image size) and bills memory the session uses rather than the peak it reserves, at a higher per-GB-hour rate.
The version is a per-environment setting, CDK_AGENTCORE_RUNTIME_PLATFORM_VERSION
(V1 or V2). Switching is an in-place update of the Runtime that keeps its
id and endpoint. The engineering plan, with the measurements behind it, is
docs/specs/agentcore-runtime-v2.md.
Prerequisites
Section titled “Prerequisites”Before CDK_AGENTCORE_RUNTIME_PLATFORM_VERSION=V2 in any environment:
-
A release whose notes say V2 is selectable. Two code changes have to be deployed first, and both arrive through ordinary releases:
- the inference-api derives most resource names from
PROJECT_PREFIXat process start, so the Runtime no longer has to be sent them (a no-op while it still is), and - CDK stops sending those variables, taking the payload to roughly half the limit, and adds a synth-time check that fails any V2 deployment over it.
- the inference-api derives most resource names from
-
The payload check passes for your values. It runs in
npx jestand duringcdk synth, so a Platform Stack run that gets as far as the deploy step has passed it. To see your own number before flipping anything:Terminal window cd infrastructure && npx jest test/runtime-environment-payload-guard.test.ts --silent=false --verbose 2>&1 | grep env-payloadThe estimate errs high on purpose. If it is under 2,560 bytes, AWS will accept the update.
-
AWS CLI 2.36.46 or later on the runner. The backend deploy script refuses (exit 7) to roll an image on a CLI that does not know
platformVersion, because an older CLI would silently put the runtime back on V1. GitHub’subuntu-24.04image is fine. -
A resource-naming check with no drift warnings. After the first of the two releases, app-api and the Runtime log one line at startup comparing the names they were sent with the names
PROJECT_PREFIXderives. Look forderived environment (prefix=…): … 0 drifted. AWARNINGnaming a variable means one of your resources is not named{prefix}-{suffix}; do not proceed until it is understood.
Switching an environment
Section titled “Switching an environment”-
Set
CDK_AGENTCORE_RUNTIME_PLATFORM_VERSION=V2in the GitHub environment. -
Run
platform.yml. Synth validates the payload; the deploy updates the Runtime in place. Wait for the Runtime and itsDEFAULTendpoint to reportREADY. -
Confirm:
Terminal window aws bedrock-agentcore-control get-agent-runtime --agent-runtime-id <id> --query 'platformVersion' -
Run the next
backend.ymlas usual and check the same field again. The deploy script asserts the version did not change during the image roll (exit 8 if it did). -
Watch first turns for
424responses or doubled cold starts, and the inference-api log fortreating this as a snapshot restore, which is the expected sign that a session was restored from a snapshot.
Switch one environment at a time, dev first, and give it a week before prod.
Switching back
Section titled “Switching back”Set the variable to V1 and run platform.yml. The property is always written
explicitly, V1 included, so this is a deterministic in-place update.
Recovery runbook
Section titled “Recovery runbook”If a Runtime update leaves the stack in UPDATE_ROLLBACK_FAILED:
-
Set
CDK_AGENTCORE_RUNTIME_PLATFORM_VERSIONback toV1(or the last working value) in the GitHub environment, so the next deploy does not repeat the failure. -
Restore the runtime directly. Read the last
READYversion withget-agent-runtime --agent-runtime-version <n>, keep the fieldsUpdateAgentRuntimeaccepts, setplatformVersiontoV1, and callupdate-agent-runtime. Wait for the runtime and theDEFAULTendpoint to reportREADY. -
Tell CloudFormation to skip the runtime, because step 2 already put it in a good state:
Terminal window aws cloudformation continue-update-rollback --stack-name <stack> --resources-to-skip <runtime logical id> -
Re-run the failed Platform Stack deploy. It writes the explicit
PlatformVersionand the current image, and brings CloudFormation’s record back in line with the runtime.
On dev this took about ten minutes.
Upgrading across the variable change
Section titled “Upgrading across the variable change”The release that stops sending the Runtime its resource names needs an inference-api image that can derive them, which means one from the previous release or later. CloudFormation re-registers the Runtime with whatever image is live, so the order of the two deploys matters once.
You don’t have to get it right by hand. Before cdk deploy, the Platform Stack
deploy reads a label off the live inference-api image. If the image is too old,
it stops without changing anything:
Runtime image cannot derive its resource names: ... Run the Backend Deploy workflow (backend.yml) first ...Run backend.yml, then re-run platform.yml. If your deploy credentials can’t
read ECR, or you run a custom image, the error says so; after confirming the
backend deploy has landed, set the GitHub variable
SKIP_RUNTIME_ENV_CONTRACT_CHECK=true for one run.
What changes for operators of the Runtime’s environment
Section titled “What changes for operators of the Runtime’s environment”Starting with the release after 1.27.0, the inference-api fills in any
resource-name variable the Runtime does not send, from PROJECT_PREFIX (and,
for three S3 buckets, the AWS account id). The list is
derived_environment.json.
A variable that is set always wins, so:
- a local
backend/src/.envcan still point one name anywhere; - a deployment that has renamed one of these resources must keep sending that variable explicitly (the startup drift warning will name it);
- nothing changes for app-api, which keeps every variable (ECS has no payload limit).