cdk-local 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1278,7 +1278,7 @@ function notFoundError$2(target, stack, resources) {
1278
1278
  function extractRuntimeProperties(stack, logicalId, resource, resources, imageContext) {
1279
1279
  const props = resource.Properties ?? {};
1280
1280
  const protocol = extractProtocol(props["ProtocolConfiguration"], logicalId, stack.stackName);
1281
- const containerUri = extractContainerUri(props["AgentRuntimeArtifact"], logicalId, stack.stackName, resources, stack.region, imageContext);
1281
+ const artifact = extractArtifact(props["AgentRuntimeArtifact"], logicalId, stack.stackName, resources, stack.region, imageContext);
1282
1282
  const environmentVariables = props["EnvironmentVariables"] && typeof props["EnvironmentVariables"] === "object" && !Array.isArray(props["EnvironmentVariables"]) ? props["EnvironmentVariables"] : {};
1283
1283
  const roleArn = typeof props["RoleArn"] === "string" ? props["RoleArn"] : void 0;
1284
1284
  const jwtAuthorizer = extractJwtAuthorizer(props["AuthorizerConfiguration"], logicalId);
@@ -1286,7 +1286,7 @@ function extractRuntimeProperties(stack, logicalId, resource, resources, imageCo
1286
1286
  stack,
1287
1287
  logicalId,
1288
1288
  resource,
1289
- containerUri,
1289
+ ...artifact.kind === "container" ? { containerUri: artifact.containerUri } : { codeArtifact: artifact.codeArtifact },
1290
1290
  environmentVariables,
1291
1291
  protocol,
1292
1292
  ...roleArn !== void 0 && { roleArn },
@@ -1330,19 +1330,50 @@ function extractProtocol(value, logicalId, stackName) {
1330
1330
  return value;
1331
1331
  }
1332
1332
  /**
1333
- * Extract + resolve the container image URI from `AgentRuntimeArtifact`.
1334
- * Rejects the `CodeConfiguration` artifact (S3 zip + managed runtime),
1335
- * which has no Dockerfile and is deferred from v1.
1333
+ * Resolve `AgentRuntimeArtifact` to either a container image URI or a code
1334
+ * artifact (managed runtime). A `ContainerConfiguration` yields the resolved
1335
+ * `ContainerUri`; a `CodeConfiguration` yields its `Runtime` / `EntryPoint` +
1336
+ * the cdk.out asset hash the command uses to locate the bundle source.
1336
1337
  */
1337
- function extractContainerUri(artifact, logicalId, stackName, resources, region, imageContext) {
1338
+ function extractArtifact(artifact, logicalId, stackName, resources, region, imageContext) {
1338
1339
  if (!artifact || typeof artifact !== "object" || Array.isArray(artifact)) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has no AgentRuntimeArtifact.`);
1339
1340
  const art = artifact;
1340
- if (art["CodeConfiguration"] && !art["ContainerConfiguration"]) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} uses a code artifact (CodeConfiguration). ${getEmbedConfig().cliName} invoke-agentcore v1 runs container artifacts only — running a managed-runtime code artifact locally needs a from-source build that is not yet supported. Build the agent as a container (e.g. AgentCoreRuntime fromAsset / a Dockerfile) to run it locally.`);
1341
+ if (art["CodeConfiguration"] && !art["ContainerConfiguration"]) return {
1342
+ kind: "code",
1343
+ codeArtifact: extractCodeArtifact(art["CodeConfiguration"], logicalId, stackName)
1344
+ };
1341
1345
  const container = art["ContainerConfiguration"];
1342
1346
  if (!container || typeof container !== "object" || Array.isArray(container)) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has no ContainerConfiguration in its AgentRuntimeArtifact.`);
1343
1347
  const uri = resolveImageUri(container["ContainerUri"], resources, region, imageContext);
1344
1348
  if (uri === void 0) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has a ContainerConfiguration.ContainerUri that ${getEmbedConfig().cliName} invoke-agentcore cannot resolve. v1 resolves a literal image URI, an Fn::Sub asset URI (the fromAsset / Dockerfile path), and an imported-ECR Fn::Join. A same-stack AWS::ECR::Repository reference is not supported — build the agent as a fromAsset image, or pin a literal / imported ECR image URI.`);
1345
- return uri;
1349
+ return {
1350
+ kind: "container",
1351
+ containerUri: uri
1352
+ };
1353
+ }
1354
+ /**
1355
+ * Extract a `CodeConfiguration` (managed-runtime) artifact. Reads `Runtime`,
1356
+ * `EntryPoint`, and the cdk.out file-asset hash from `Code.S3.Prefix`
1357
+ * (`<hash>.zip`, the `fromCodeAsset` shape). A non-literal `Code.S3.Prefix`
1358
+ * (an intrinsic, or a `fromS3` object key the command can't map to a local
1359
+ * asset) hard-errors — downloading a pre-existing S3 bundle is not supported
1360
+ * locally yet.
1361
+ */
1362
+ function extractCodeArtifact(codeConfig, logicalId, stackName) {
1363
+ const cfg = codeConfig && typeof codeConfig === "object" && !Array.isArray(codeConfig) ? codeConfig : {};
1364
+ const runtime = cfg["Runtime"];
1365
+ if (typeof runtime !== "string" || runtime.length === 0) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has a CodeConfiguration with no string Runtime.`);
1366
+ const entryPointRaw = cfg["EntryPoint"];
1367
+ const entryPoint = Array.isArray(entryPointRaw) ? entryPointRaw.filter((x) => typeof x === "string") : [];
1368
+ if (entryPoint.length === 0) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has a CodeConfiguration with no EntryPoint.`);
1369
+ const s3 = cfg["Code"] && typeof cfg["Code"] === "object" ? cfg["Code"]["S3"] : void 0;
1370
+ const prefix = s3 && typeof s3 === "object" ? s3["Prefix"] : void 0;
1371
+ if (typeof prefix !== "string" || prefix.length === 0) throw new AgentCoreResolutionError(`AgentCore Runtime '${logicalId}' in ${stackName} has a CodeConfiguration whose Code.S3.Prefix is not a literal string. ${getEmbedConfig().cliName} invoke-agentcore runs a local from-source build of the fromCodeAsset bundle; downloading a pre-existing S3 bundle (fromS3) is not supported yet.`);
1372
+ return {
1373
+ runtime,
1374
+ entryPoint,
1375
+ codeAssetHash: prefix.replace(/^.*\//, "").replace(/\.zip$/, "")
1376
+ };
1346
1377
  }
1347
1378
  /**
1348
1379
  * Resolve a `ContainerUri` value to a string. Handles a literal string,
@@ -8142,6 +8173,116 @@ function createLocalInvokeCommand(opts = {}) {
8142
8173
  return invoke;
8143
8174
  }
8144
8175
 
8176
+ //#endregion
8177
+ //#region src/local/agentcore-code-build.ts
8178
+ /**
8179
+ * Local from-source build for an AgentCore Runtime `CodeConfiguration`
8180
+ * (managed-runtime) artifact.
8181
+ *
8182
+ * Unlike the container artifact (which ships its own Dockerfile/image), a code
8183
+ * artifact is just source + an `EntryPoint` + a `Runtime`; AWS's managed
8184
+ * runtime runs the entrypoint, which self-serves the AgentCore HTTP contract
8185
+ * (`POST /invocations` + `GET /ping` on 8080) — typically via the
8186
+ * `bedrock-agentcore` SDK. We replicate that locally: generate a Dockerfile
8187
+ * for the runtime's base image, install the bundle's dependencies, and run the
8188
+ * entrypoint. The resulting container speaks the same 8080 contract, so the
8189
+ * existing HTTP client drives it unchanged.
8190
+ */
8191
+ /** AgentCore CodeConfiguration `Runtime` enum → local Docker base image. */
8192
+ const RUNTIME_BASE_IMAGES = {
8193
+ PYTHON_3_10: "public.ecr.aws/docker/library/python:3.10-slim",
8194
+ PYTHON_3_11: "public.ecr.aws/docker/library/python:3.11-slim",
8195
+ PYTHON_3_12: "public.ecr.aws/docker/library/python:3.12-slim",
8196
+ PYTHON_3_13: "public.ecr.aws/docker/library/python:3.13-slim",
8197
+ PYTHON_3_14: "public.ecr.aws/docker/library/python:3.14-slim",
8198
+ NODE_22: "public.ecr.aws/docker/library/node:22-slim"
8199
+ };
8200
+ /** Runtimes this CLI can build a from-source image for. */
8201
+ const SUPPORTED_CODE_RUNTIMES = Object.keys(RUNTIME_BASE_IMAGES);
8202
+ /**
8203
+ * Build (or, with `noBuild`, verify) a local image for a code artifact and
8204
+ * return its tag. The generated Dockerfile is written to a temp dir and built
8205
+ * with the source dir as the context, so the cdk.out asset is never mutated.
8206
+ */
8207
+ async function buildAgentCoreCodeImage(options) {
8208
+ const logger = getLogger();
8209
+ const base = RUNTIME_BASE_IMAGES[options.runtime];
8210
+ if (!base) throw new LocalInvokeBuildError(`AgentCore CodeConfiguration runtime '${options.runtime}' is not supported for local execution. Supported runtimes: ${SUPPORTED_CODE_RUNTIMES.join(", ")}.`);
8211
+ const isNode = options.runtime.startsWith("NODE");
8212
+ const dockerfile = renderCodeDockerfile(base, options.entryPoint, isNode);
8213
+ const tag = computeCodeImageTag(options.sourceDir, options.runtime, options.entryPoint, dockerfile);
8214
+ const platform = options.architecture === "x86_64" ? "linux/amd64" : "linux/arm64";
8215
+ if (options.noBuild === true) {
8216
+ logger.info(`Skipping docker build (--no-build). Verifying ${tag} is in local registry...`);
8217
+ if (!await isImageInLocalCache(tag)) throw new LocalInvokeBuildError(`image '${tag}' not in local registry and --no-build is set; remove --no-build or run the build manually first.`);
8218
+ return tag;
8219
+ }
8220
+ logger.info(`Building agent image from source (runtime=${options.runtime}, platform=${platform})...`);
8221
+ logger.debug(`Local tag: ${tag}`);
8222
+ const buildDir = await mkdtemp(join(tmpdir(), `${getEmbedConfig().resourceNamePrefix}-agentcore-code-`));
8223
+ const dockerfilePath = join(buildDir, "Dockerfile");
8224
+ try {
8225
+ await writeFile(dockerfilePath, dockerfile, "utf-8");
8226
+ await runDockerStreaming([
8227
+ "build",
8228
+ "--platform",
8229
+ platform,
8230
+ "--tag",
8231
+ tag,
8232
+ "--file",
8233
+ dockerfilePath,
8234
+ options.sourceDir
8235
+ ]);
8236
+ } catch (err) {
8237
+ const stderr = err.stderr?.trim();
8238
+ throw new LocalInvokeBuildError(`docker build failed for AgentCore code artifact (${options.sourceDir})${stderr ? `: ${stderr}` : ""}`);
8239
+ } finally {
8240
+ await rm(buildDir, {
8241
+ recursive: true,
8242
+ force: true
8243
+ }).catch(() => void 0);
8244
+ }
8245
+ return tag;
8246
+ }
8247
+ /**
8248
+ * Render the generated Dockerfile. Dependencies are installed conditionally
8249
+ * (a bundle may vendor them or ship none), and the EntryPoint is mapped to a
8250
+ * CMD: a bare script (`app.py` / `server.js`) is run by the interpreter, while
8251
+ * an explicit launcher (e.g. `opentelemetry-instrument`) is run verbatim.
8252
+ */
8253
+ function renderCodeDockerfile(base, entryPoint, isNode) {
8254
+ const installStep = isNode ? "RUN if [ -f package.json ]; then npm install --omit=dev; fi" : "RUN if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; elif [ -f pyproject.toml ]; then pip install --no-cache-dir .; fi";
8255
+ return [
8256
+ `FROM ${base}`,
8257
+ "WORKDIR /app",
8258
+ "COPY . /app",
8259
+ installStep,
8260
+ "EXPOSE 8080",
8261
+ `CMD ${JSON.stringify(toCmdArgv(entryPoint, isNode))}`
8262
+ ].join("\n") + "\n";
8263
+ }
8264
+ /**
8265
+ * Map the EntryPoint argv to a Docker CMD argv. The managed runtime execs the
8266
+ * entrypoint as the program; a bare script file is run by the language
8267
+ * interpreter (`python` / `node`), while a non-script first token (a launcher
8268
+ * already on PATH, e.g. `opentelemetry-instrument`) is run verbatim.
8269
+ */
8270
+ function toCmdArgv(entryPoint, isNode) {
8271
+ const first = entryPoint[0] ?? "";
8272
+ if (!(isNode ? /\.[cm]?js$/.test(first) : /\.py$/.test(first))) return entryPoint;
8273
+ return [isNode ? "node" : "python", ...entryPoint];
8274
+ }
8275
+ /** Deterministic local tag, stable for identical source + runtime + entrypoint. */
8276
+ function computeCodeImageTag(sourceDir, runtime, entryPoint, dockerfile) {
8277
+ const hash = createHash("sha256").update([
8278
+ sourceDir,
8279
+ runtime,
8280
+ entryPoint.join(" "),
8281
+ dockerfile
8282
+ ].join("\0")).digest("hex").slice(0, 16);
8283
+ return `${getEmbedConfig().resourceNamePrefix}-agentcore-code-${hash}`;
8284
+ }
8285
+
8145
8286
  //#endregion
8146
8287
  //#region src/local/agentcore-client.ts
8147
8288
  /**
@@ -17461,9 +17602,10 @@ function createLocalStartApiCommand(opts = {}) {
17461
17602
  * locally and invoke it once over the AgentCore HTTP contract. Resolves
17462
17603
  * the `AWS::BedrockAgentCore::Runtime`, pulls / builds its container,
17463
17604
  * starts it on port 8080, waits for `GET /ping`, POSTs the event to
17464
- * `POST /invocations`, prints the response, and tears down. v1 covers the
17465
- * container artifact + HTTP protocol; the agent's calls to real AWS go to
17466
- * real AWS (credentials injected like `cdkl invoke`).
17605
+ * `POST /invocations`, prints the response, and tears down. Covers the
17606
+ * container artifact and the CodeConfiguration managed-runtime artifact
17607
+ * (fromCodeAsset, built from source) on the HTTP + MCP protocols; the agent's
17608
+ * calls to real AWS go to real AWS (credentials injected like `cdkl invoke`).
17467
17609
  */
17468
17610
  async function localInvokeAgentCoreCommand(target, options, extraStateProviders) {
17469
17611
  const logger = getLogger();
@@ -17606,36 +17748,74 @@ async function resolveInboundAuthorization(resolved, options) {
17606
17748
  return header;
17607
17749
  }
17608
17750
  /**
17609
- * Acquire the agent container image. Mirrors the container-Lambda path:
17610
- * build from a local cdk.out asset when the URI matches one, else pull
17611
- * from ECR, else pull a plain registry image.
17751
+ * Acquire the agent image. A CODE artifact (managed runtime) is built from
17752
+ * source (generated Dockerfile over the bundle's cdk.out asset). A CONTAINER
17753
+ * artifact mirrors the container-Lambda path: build from a local cdk.out asset
17754
+ * when the URI matches one, else pull from ECR, else pull a plain registry image.
17612
17755
  */
17613
17756
  async function resolveAgentCoreImage(resolved, options) {
17614
17757
  const logger = getLogger();
17615
17758
  const architecture = platformToArchitecture(options.platform);
17759
+ if (resolved.codeArtifact) return resolveAgentCoreCodeImage(resolved, resolved.codeArtifact, options, architecture);
17760
+ const containerUri = resolved.containerUri;
17761
+ if (containerUri === void 0) throw new CdkLocalError(`AgentCore Runtime '${resolved.logicalId}' has neither a container image nor a code artifact to run.`, "LOCAL_INVOKE_AGENTCORE_NO_ARTIFACT");
17616
17762
  const manifestPath = resolved.stack.assetManifestPath;
17617
17763
  if (manifestPath) {
17618
17764
  const cdkOutDir = dirname(manifestPath);
17619
17765
  const manifest = await new AssetManifestLoader().loadManifest(cdkOutDir, resolved.stack.stackName);
17620
17766
  if (manifest) {
17621
- const entry = getDockerImageBySourceHash(manifest, resolved.containerUri);
17767
+ const entry = getDockerImageBySourceHash(manifest, containerUri);
17622
17768
  if (entry) return buildContainerImage(entry.asset, cdkOutDir, {
17623
17769
  architecture,
17624
17770
  noBuild: options.build === false
17625
17771
  });
17626
17772
  }
17627
17773
  }
17628
- if (parseEcrUri(resolved.containerUri)) {
17629
- logger.info(`Pulling agent image from ECR: ${resolved.containerUri}`);
17630
- return pullEcrImage(resolved.containerUri, {
17774
+ if (parseEcrUri(containerUri)) {
17775
+ logger.info(`Pulling agent image from ECR: ${containerUri}`);
17776
+ return pullEcrImage(containerUri, {
17631
17777
  skipPull: options.pull === false,
17632
17778
  ...options.region !== void 0 && { region: options.region },
17633
17779
  ...options.ecrRoleArn !== void 0 && { ecrRoleArn: options.ecrRoleArn },
17634
17780
  ...options.profile !== void 0 && { profile: options.profile }
17635
17781
  });
17636
17782
  }
17637
- await pullImage(resolved.containerUri, options.pull === false);
17638
- return resolved.containerUri;
17783
+ await pullImage(containerUri, options.pull === false);
17784
+ return containerUri;
17785
+ }
17786
+ /**
17787
+ * Build a local image from a `CodeConfiguration` (managed-runtime) bundle:
17788
+ * locate the fromCodeAsset source dir in cdk.out via its asset hash, then run
17789
+ * the from-source build (generated Dockerfile → install deps → run EntryPoint).
17790
+ * A bundle with no local asset (fromS3) hard-errors — not supported yet.
17791
+ */
17792
+ async function resolveAgentCoreCodeImage(resolved, code, options, architecture) {
17793
+ const manifestPath = resolved.stack.assetManifestPath;
17794
+ if (!manifestPath) throw new CdkLocalError(`AgentCore Runtime '${resolved.logicalId}' uses a code artifact, but its stack has no asset manifest in cdk.out to read the bundle source from.`, "LOCAL_INVOKE_AGENTCORE_CODE_NO_MANIFEST");
17795
+ const cdkOutDir = dirname(manifestPath);
17796
+ const loader = new AssetManifestLoader();
17797
+ const manifest = await loader.loadManifest(cdkOutDir, resolved.stack.stackName);
17798
+ const fileAssets = manifest ? loader.getFileAssets(manifest) : void 0;
17799
+ const asset = fileAssets ? fileAssets.get(code.codeAssetHash) ?? findFileAssetByObjectKey(fileAssets, code.codeAssetHash) : void 0;
17800
+ if (!asset) throw new CdkLocalError(`AgentCore Runtime '${resolved.logicalId}' code bundle (asset ${code.codeAssetHash}) was not found in the cdk.out asset manifest. ${getEmbedConfig().cliName} invoke-agentcore runs a local from-source build of a fromCodeAsset bundle; a fromS3 bundle (a pre-existing S3 object) is not supported yet.`, "LOCAL_INVOKE_AGENTCORE_CODE_ASSET_NOT_FOUND");
17801
+ const sourceDir = loader.getAssetSourcePath(cdkOutDir, asset);
17802
+ if (!existsSync(sourceDir) || !statSync(sourceDir).isDirectory()) throw new CdkLocalError(`AgentCore Runtime '${resolved.logicalId}' code bundle source '${sourceDir}' does not exist or is not a directory. Re-synthesize the app and retry.`, "LOCAL_INVOKE_AGENTCORE_CODE_SOURCE_MISSING");
17803
+ return buildAgentCoreCodeImage({
17804
+ sourceDir,
17805
+ runtime: code.runtime,
17806
+ entryPoint: code.entryPoint,
17807
+ architecture,
17808
+ noBuild: options.build === false
17809
+ });
17810
+ }
17811
+ /**
17812
+ * Find the file asset whose destination objectKey is `<hash>.zip` (matching the
17813
+ * `Code.S3.Prefix`'s hash) when the source-hash-keyed lookup misses — covers a
17814
+ * synthesizer whose source hash differs from the destination objectKey.
17815
+ */
17816
+ function findFileAssetByObjectKey(fileAssets, hash) {
17817
+ const zip = `${hash}.zip`;
17818
+ for (const asset of fileAssets.values()) if (Object.values(asset.destinations).some((d) => d.objectKey === zip || d.objectKey.endsWith(`/${zip}`))) return asset;
17639
17819
  }
17640
17820
  /**
17641
17821
  * Build the container env: resolved template env vars (+ `--env-vars`
@@ -17858,7 +18038,7 @@ function readEnvOverridesFile$2(filePath) {
17858
18038
  }
17859
18039
  function createLocalInvokeAgentCoreCommand(opts = {}) {
17860
18040
  setEmbedConfig(opts.embedConfig);
17861
- const cmd = new Command("invoke-agentcore").description("Run a Bedrock AgentCore Runtime container locally and invoke it once over its protocol contract: HTTP (POST /invocations + GET /ping on 8080) or MCP (POST /mcp Streamable HTTP on 8000). Resolves the AWS::BedrockAgentCore::Runtime, pulls/builds its container, injects env vars + AWS credentials, and prints the response. For an MCP runtime, runs the session handshake then sends one JSON-RPC request (tools/list by default, or the method/params from --event). Target accepts a CDK display path (MyStack/MyAgent) or stack-qualified logical ID (MyStack:MyAgentRuntime1234). Single-stack apps may omit the stack prefix. Omit <target> in an interactive terminal to pick from a list. Supports the container artifact on the HTTP + MCP protocols; the agent calls real AWS for managed services.").argument("[target]", "CDK display path or stack-qualified logical ID of the AgentCore Runtime to invoke (omit to pick interactively in a TTY)").addOption(new Option("-e, --event <file>", "JSON event payload file (default: {})")).addOption(new Option("--event-stdin", "Read event JSON from stdin").default(false)).addOption(new Option("--env-vars <file>", "JSON env-var overrides (SAM-compatible: {\"LogicalId\":{\"KEY\":\"VALUE\"}})")).addOption(new Option("--session-id <id>", "AgentCore runtime session id header value (default: a random UUID)")).addOption(new Option("--bearer-token <jwt>", "Bearer JWT to present when the runtime declares a customJwtAuthorizer. Verified against the runtime OIDC discovery URL (signature / issuer / expiry / audience) before the container starts, then forwarded to /invocations as Authorization: Bearer <jwt>.")).addOption(new Option("--no-verify-auth", "Skip inbound JWT verification even when the runtime declares a customJwtAuthorizer (local-dev escape hatch). A --bearer-token, if given, is still forwarded.")).addOption(new Option("--platform <platform>", "docker --platform for the agent container (linux/amd64 or linux/arm64)").choices(["linux/amd64", "linux/arm64"]).default("linux/arm64")).addOption(new Option("--no-pull", "Skip docker pull (use cached image) — no-op for the local-build path")).addOption(new Option("--no-build", "Skip docker build on the local-asset path (use the previously-built tag). No-op for the ECR / registry pull paths.")).addOption(new Option("--container-host <host>", "Host to bind the agent port to").default("127.0.0.1")).addOption(new Option("--assume-role [arn]", "Assume the runtime's execution role and forward STS-issued temp credentials to the container so the agent runs with the deployed role. Three forms: (1) `--assume-role <arn>` assumes the explicit ARN; (2) `--assume-role` (bare) uses the runtime's RoleArn when it is a literal ARN; (3) `--no-assume-role` opts out. Off by default — the developer's shell credentials are forwarded unchanged.")).addOption(new Option("--ecr-role-arn <arn>", "Role ARN to assume before authenticating against ECR for cross-account / centralized registries. Same-account / same-region pulls do not need this flag.")).addOption(new Option("--from-cfn-stack [cfn-stack-name]", "Read a deployed CloudFormation stack via ListStackResources and substitute Ref / Fn::ImportValue in env vars with the deployed physical IDs / exports. Bare form uses the resolved stack name; pass an explicit value when the CFn stack name differs.")).addOption(new Option("--stack-region <region>", "Region of the state record to read. Used with --from-cfn-stack as the CFn client region.")).action(withErrorHandling(async (target, options) => {
18041
+ const cmd = new Command("invoke-agentcore").description("Run a Bedrock AgentCore Runtime container locally and invoke it once over its protocol contract: HTTP (POST /invocations + GET /ping on 8080) or MCP (POST /mcp Streamable HTTP on 8000). Resolves the AWS::BedrockAgentCore::Runtime, pulls/builds its container, injects env vars + AWS credentials, and prints the response. For an MCP runtime, runs the session handshake then sends one JSON-RPC request (tools/list by default, or the method/params from --event). Target accepts a CDK display path (MyStack/MyAgent) or stack-qualified logical ID (MyStack:MyAgentRuntime1234). Single-stack apps may omit the stack prefix. Omit <target> in an interactive terminal to pick from a list. Supports the container artifact and the CodeConfiguration managed-runtime artifact (fromCodeAsset, built from source) on the HTTP + MCP protocols; the agent calls real AWS for managed services.").argument("[target]", "CDK display path or stack-qualified logical ID of the AgentCore Runtime to invoke (omit to pick interactively in a TTY)").addOption(new Option("-e, --event <file>", "JSON event payload file (default: {})")).addOption(new Option("--event-stdin", "Read event JSON from stdin").default(false)).addOption(new Option("--env-vars <file>", "JSON env-var overrides (SAM-compatible: {\"LogicalId\":{\"KEY\":\"VALUE\"}})")).addOption(new Option("--session-id <id>", "AgentCore runtime session id header value (default: a random UUID)")).addOption(new Option("--bearer-token <jwt>", "Bearer JWT to present when the runtime declares a customJwtAuthorizer. Verified against the runtime OIDC discovery URL (signature / issuer / expiry / audience) before the container starts, then forwarded to /invocations as Authorization: Bearer <jwt>.")).addOption(new Option("--no-verify-auth", "Skip inbound JWT verification even when the runtime declares a customJwtAuthorizer (local-dev escape hatch). A --bearer-token, if given, is still forwarded.")).addOption(new Option("--platform <platform>", "docker --platform for the agent container (linux/amd64 or linux/arm64)").choices(["linux/amd64", "linux/arm64"]).default("linux/arm64")).addOption(new Option("--no-pull", "Skip docker pull (use cached image) — no-op for the local-build path")).addOption(new Option("--no-build", "Skip docker build on the local-asset path (use the previously-built tag). No-op for the ECR / registry pull paths.")).addOption(new Option("--container-host <host>", "Host to bind the agent port to").default("127.0.0.1")).addOption(new Option("--assume-role [arn]", "Assume the runtime's execution role and forward STS-issued temp credentials to the container so the agent runs with the deployed role. Three forms: (1) `--assume-role <arn>` assumes the explicit ARN; (2) `--assume-role` (bare) uses the runtime's RoleArn when it is a literal ARN; (3) `--no-assume-role` opts out. Off by default — the developer's shell credentials are forwarded unchanged.")).addOption(new Option("--ecr-role-arn <arn>", "Role ARN to assume before authenticating against ECR for cross-account / centralized registries. Same-account / same-region pulls do not need this flag.")).addOption(new Option("--from-cfn-stack [cfn-stack-name]", "Read a deployed CloudFormation stack via ListStackResources and substitute Ref / Fn::ImportValue in env vars with the deployed physical IDs / exports. Bare form uses the resolved stack name; pass an explicit value when the CFn stack name differs.")).addOption(new Option("--stack-region <region>", "Region of the state record to read. Used with --from-cfn-stack as the CFn client region.")).action(withErrorHandling(async (target, options) => {
17862
18042
  await localInvokeAgentCoreCommand(target, options, opts.extraStateProviders);
17863
18043
  }));
17864
18044
  [
@@ -21592,5 +21772,5 @@ function createLocalListCommand(opts = {}) {
21592
21772
  }
21593
21773
 
21594
21774
  //#endregion
21595
- export { createJwksCache as $, resolveAgentCoreTarget as $t, invokeTokenAuthorizer as A, LocalStateSourceError as At, VtlEvaluationError as B, resolveWatchConfig as Bt, resolveSelectionExpression as C, EcsTaskResolutionError as Ct, computeRequestIdentityHash as D, substituteEnvVarsFromStateAsync as Dt, buildMethodArn as E, substituteEnvVarsFromState as Et, buildRestV1Event as F, resolveCfnRegion as Ft, buildMgmtEndpointEnvUrl as G, parseSelectionExpressionPath as Gt, probeHostGatewaySupport as H, listTargets as Ht, evaluateResponseParameters as I, resolveCfnStackName as It, buildConnectEvent as J, resolveLambdaArnIntrinsic as Jt, handleConnectionsRequest as K, discoverRoutes as Kt, pickResponseTemplate as L, CfnLocalStateProvider as Lt, translateLambdaResponse as M, isCfnFlagPresent as Mt, applyAuthorizerOverlay as N, rejectExplicitCfnStackWithMultipleStacks as Nt, evaluateCachedLambdaPolicy as O, resolveEnvVars as Ot, buildHttpApiV2Event as P, resolveCfnFallbackRegion as Pt, buildJwksUrlFromIssuer as Q, AgentCoreResolutionError as Qt, selectIntegrationResponse as R, collectSsmParameterRefs as Rt, startApiServer as S, resolveRuntimeImage as St, defaultCredentialsLoader as T, substituteAgainstStateAsync as Tt, bufferToBody as U, discoverWebSocketApis as Ut, HOST_GATEWAY_MIN_VERSION as V, countTargets as Vt, ConnectionRegistry as W, discoverWebSocketApisOrThrow as Wt, buildMessageEvent as X, AGENTCORE_MCP_PROTOCOL as Xt, buildDisconnectEvent as Y, AGENTCORE_HTTP_PROTOCOL as Yt, buildCognitoJwksUrl as Z, AGENTCORE_RUNTIME_TYPE as Zt, availableApiIdentifiers as _, createLocalInvokeCommand as _t, buildCloudMapIndex as a, buildCorsConfigByApiId as at, groupRoutesByServer as b, resolveRuntimeCodeMountPath as bt, createLocalRunTaskCommand as c, matchPreflight as ct, createWatchPredicates as d, MCP_PROTOCOL_VERSION as dt, derivePseudoParametersFromRegion as en, verifyCognitoJwt as et, resolveApiTargetSubset as f, mcpInvokeOnce as ft, buildStageMap as g, waitForAgentCorePing as gt, attachStageContext as h, invokeAgentCore as ht, createLocalStartServiceCommand as i, applyCorsResponseHeaders as it, matchRoute as j, createLocalStateProvider as jt, invokeRequestAuthorizer as k, materializeLayerFromArn as kt, createLocalInvokeAgentCoreCommand as l, MCP_CONTAINER_PORT as lt, createFileWatcher as m, AGENTCORE_SESSION_ID_HEADER as mt, formatTargetListing as n, tryResolveImageFnJoin as nn, verifyJwtViaDiscovery as nt, CloudMapRegistry as o, buildCorsConfigFromCloudFrontChain as ot, createAuthorizerCache as p, parseSseForJsonRpc as pt, parseConnectionsPath as q, pickRefLogicalId as qt, createLocalStartAlbCommand as r, LocalInvokeBuildError as rn, attachAuthorizers as rt, getContainerNetworkIp as s, isFunctionUrlOacFronted as st, createLocalListCommand as t, substituteImagePlaceholders as tn, verifyJwtAuthorizer as tt, createLocalStartApiCommand as u, MCP_PATH as ut, filterRoutesByApiIdentifier as v, architectureToPlatform as vt, resolveServiceIntegrationParameters as w, substituteAgainstState as wt, readMtlsMaterialsFromDisk as x, resolveRuntimeFileExtension as xt, filterRoutesByApiIdentifiers as y, buildContainerImage as yt, tryParseStatus as z, resolveSsmParameters as zt };
21596
- //# sourceMappingURL=local-list-qObdm4O8.js.map
21775
+ export { createJwksCache as $, resolveLambdaArnIntrinsic as $t, invokeTokenAuthorizer as A, substituteAgainstStateAsync as At, VtlEvaluationError as B, resolveCfnRegion as Bt, resolveSelectionExpression as C, architectureToPlatform as Ct, computeRequestIdentityHash as D, resolveRuntimeImage as Dt, buildMethodArn as E, resolveRuntimeFileExtension as Et, buildRestV1Event as F, LocalStateSourceError as Ft, buildMgmtEndpointEnvUrl as G, resolveWatchConfig as Gt, probeHostGatewaySupport as H, CfnLocalStateProvider as Ht, evaluateResponseParameters as I, createLocalStateProvider as It, buildConnectEvent as J, discoverWebSocketApis as Jt, handleConnectionsRequest as K, countTargets as Kt, pickResponseTemplate as L, isCfnFlagPresent as Lt, translateLambdaResponse as M, substituteEnvVarsFromStateAsync as Mt, applyAuthorizerOverlay as N, resolveEnvVars as Nt, evaluateCachedLambdaPolicy as O, EcsTaskResolutionError as Ot, buildHttpApiV2Event as P, materializeLayerFromArn as Pt, buildJwksUrlFromIssuer as Q, pickRefLogicalId as Qt, selectIntegrationResponse as R, rejectExplicitCfnStackWithMultipleStacks as Rt, startApiServer as S, createLocalInvokeCommand as St, defaultCredentialsLoader as T, resolveRuntimeCodeMountPath as Tt, bufferToBody as U, collectSsmParameterRefs as Ut, HOST_GATEWAY_MIN_VERSION as V, resolveCfnStackName as Vt, ConnectionRegistry as W, resolveSsmParameters as Wt, buildMessageEvent as X, parseSelectionExpressionPath as Xt, buildDisconnectEvent as Y, discoverWebSocketApisOrThrow as Yt, buildCognitoJwksUrl as Z, discoverRoutes as Zt, availableApiIdentifiers as _, SUPPORTED_CODE_RUNTIMES as _t, buildCloudMapIndex as a, derivePseudoParametersFromRegion as an, buildCorsConfigByApiId as at, groupRoutesByServer as b, renderCodeDockerfile as bt, createLocalRunTaskCommand as c, LocalInvokeBuildError as cn, matchPreflight as ct, createWatchPredicates as d, MCP_PROTOCOL_VERSION as dt, AGENTCORE_HTTP_PROTOCOL as en, verifyCognitoJwt as et, resolveApiTargetSubset as f, mcpInvokeOnce as ft, buildStageMap as g, waitForAgentCorePing as gt, attachStageContext as h, invokeAgentCore as ht, createLocalStartServiceCommand as i, resolveAgentCoreTarget as in, applyCorsResponseHeaders as it, matchRoute as j, substituteEnvVarsFromState as jt, invokeRequestAuthorizer as k, substituteAgainstState as kt, createLocalInvokeAgentCoreCommand as l, MCP_CONTAINER_PORT as lt, createFileWatcher as m, AGENTCORE_SESSION_ID_HEADER as mt, formatTargetListing as n, AGENTCORE_RUNTIME_TYPE as nn, verifyJwtViaDiscovery as nt, CloudMapRegistry as o, substituteImagePlaceholders as on, buildCorsConfigFromCloudFrontChain as ot, createAuthorizerCache as p, parseSseForJsonRpc as pt, parseConnectionsPath as q, listTargets as qt, createLocalStartAlbCommand as r, AgentCoreResolutionError as rn, attachAuthorizers as rt, getContainerNetworkIp as s, tryResolveImageFnJoin as sn, isFunctionUrlOacFronted as st, createLocalListCommand as t, AGENTCORE_MCP_PROTOCOL as tn, verifyJwtAuthorizer as tt, createLocalStartApiCommand as u, MCP_PATH as ut, filterRoutesByApiIdentifier as v, buildAgentCoreCodeImage as vt, resolveServiceIntegrationParameters as w, buildContainerImage as wt, readMtlsMaterialsFromDisk as x, toCmdArgv as xt, filterRoutesByApiIdentifiers as y, computeCodeImageTag as yt, tryParseStatus as z, resolveCfnFallbackRegion as zt };
21776
+ //# sourceMappingURL=local-list-bwZnI2pV.js.map