@go-to-k/cdkd 0.161.0 → 0.161.1

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.
package/dist/cli.js CHANGED
@@ -42081,6 +42081,55 @@ function createLocalStateProvider(options, cdkdStackName, synthRegion) {
42081
42081
  //#endregion
42082
42082
  //#region src/local/intrinsic-image.ts
42083
42083
  /**
42084
+ * Derive the AWS pseudo parameters that are trivially knowable from the
42085
+ * deploy region alone, without any STS call or cdkd state load.
42086
+ * `urlSuffix` and `partition` follow the canonical AWS partition rules:
42087
+ *
42088
+ * - region prefix `cn-*` → partition `aws-cn`, urlSuffix `amazonaws.com.cn`
42089
+ * - region prefix `us-gov-*` → partition `aws-us-gov`, urlSuffix `amazonaws.com`
42090
+ * - region prefix `us-iso-*` → partition `aws-iso`, urlSuffix `c2s.ic.gov`
42091
+ * - region prefix `us-isob-*` → partition `aws-iso-b`, urlSuffix `sc2s.sgov.gov`
42092
+ * - everything else (`us-east-1` / `eu-west-2` / `ap-northeast-1` / etc.)
42093
+ * → partition `aws`, urlSuffix `amazonaws.com`
42094
+ *
42095
+ * `accountId` is optional pass-through (caller decides whether to populate
42096
+ * it). The bootstrap-ECR URI shape that `lambda.DockerImageCode.fromImageAsset`
42097
+ * synthesizes carries account-id + region as literal strings in the template,
42098
+ * so only `urlSuffix` / `partition` / `region` are required to resolve it
42099
+ * (issue #637).
42100
+ *
42101
+ * Returns `undefined` when `region` is undefined / empty so the caller can
42102
+ * fall through cleanly. The shape mirrors `ImageResolutionContext.pseudoParameters`
42103
+ * so the result drops straight into a context literal.
42104
+ */
42105
+ function derivePseudoParametersFromRegion(region, accountId) {
42106
+ if (!region || typeof region !== "string" || region.length === 0) return void 0;
42107
+ let partition;
42108
+ let urlSuffix;
42109
+ if (region.startsWith("cn-")) {
42110
+ partition = "aws-cn";
42111
+ urlSuffix = "amazonaws.com.cn";
42112
+ } else if (region.startsWith("us-gov-")) {
42113
+ partition = "aws-us-gov";
42114
+ urlSuffix = "amazonaws.com";
42115
+ } else if (region.startsWith("us-isob-")) {
42116
+ partition = "aws-iso-b";
42117
+ urlSuffix = "sc2s.sgov.gov";
42118
+ } else if (region.startsWith("us-iso-")) {
42119
+ partition = "aws-iso";
42120
+ urlSuffix = "c2s.ic.gov";
42121
+ } else {
42122
+ partition = "aws";
42123
+ urlSuffix = "amazonaws.com";
42124
+ }
42125
+ return {
42126
+ ...accountId !== void 0 && { accountId },
42127
+ region,
42128
+ partition,
42129
+ urlSuffix
42130
+ };
42131
+ }
42132
+ /**
42084
42133
  * Resolve the canonical CDK 2.x `Fn::Join` shape emitted by
42085
42134
  * `ContainerImage.fromEcrRepository(repo, tag)` (ECS) and
42086
42135
  * `lambda.DockerImageCode.fromEcr(repo, { tagOrDigest })` (Lambda
@@ -42447,7 +42496,7 @@ function extractLambdaProperties(stack, logicalId, resource, resources) {
42447
42496
  const timeoutSec = typeof props["Timeout"] === "number" ? props["Timeout"] : 3;
42448
42497
  const ephemeralStorageMb = extractEphemeralStorageMb(props, logicalId);
42449
42498
  const code = props["Code"] ?? {};
42450
- const imageUri = extractImageUri$1(code["ImageUri"], logicalId, stack.stackName, resources);
42499
+ const imageUri = extractImageUri$1(code["ImageUri"], logicalId, stack.stackName, resources, stack.region);
42451
42500
  if (imageUri !== void 0) return extractImageLambdaProperties({
42452
42501
  stack,
42453
42502
  logicalId,
@@ -42544,7 +42593,7 @@ function extractEphemeralStorageMb(props, logicalId) {
42544
42593
  * for genuinely unrecognized shapes so the caller's downstream ZIP-vs-
42545
42594
  * IMAGE branching can route to its existing error path.
42546
42595
  */
42547
- function extractImageUri$1(value, logicalId, stackName, resources) {
42596
+ function extractImageUri$1(value, logicalId, stackName, resources, region) {
42548
42597
  if (typeof value === "string" && value.length > 0) return value;
42549
42598
  if (value && typeof value === "object" && !Array.isArray(value)) {
42550
42599
  const obj = value;
@@ -42552,11 +42601,12 @@ function extractImageUri$1(value, logicalId, stackName, resources) {
42552
42601
  if (typeof sub === "string" && sub.length > 0) return sub;
42553
42602
  if (Array.isArray(sub) && typeof sub[0] === "string") return sub[0];
42554
42603
  if ("Fn::Join" in obj) {
42555
- const joinResolved = tryResolveImageFnJoin(value, resources, void 0);
42604
+ const pseudoParameters = derivePseudoParametersFromRegion(region);
42605
+ const joinResolved = tryResolveImageFnJoin(value, resources, pseudoParameters ? { pseudoParameters } : void 0);
42556
42606
  if (joinResolved.kind === "resolved") return joinResolved.uri;
42557
42607
  if (joinResolved.kind === "needs-state") throw new LocalInvokeResolutionError(`Lambda '${logicalId}' in ${stackName} references same-stack ECR repository '${joinResolved.repoLogicalId}' via Fn::Join. cdkd local invoke cannot resolve the repository URI without state — deploy the stack first (so cdkd records the repository physical id), rebuild via lambda.DockerImageCode.fromImageAsset, or pin a public image.`);
42558
42608
  if (joinResolved.kind === "unsupported-join") throw new LocalInvokeResolutionError(`Lambda '${logicalId}' in ${stackName} has an unsupported Fn::Join Code.ImageUri shape: ${joinResolved.reason}. cdkd local invoke recognizes the canonical CDK 2.x lambda.DockerImageCode.fromEcr Fn::Join shape (delimiter "" with nested Fn::Select/Fn::Split over an ECR Repository Arn GetAtt + Ref to the repo).`);
42559
- throw new LocalInvokeResolutionError(`Lambda '${logicalId}' in ${stackName} has an Fn::Join Code.ImageUri that cdkd local invoke cannot resolve. The shape likely references AWS pseudo parameters (e.g. \${AWS::URLSuffix}) for an imported ECR repository. Workarounds: rebuild via lambda.DockerImageCode.fromImageAsset, or pin a fully-literal public image URI.`);
42609
+ throw new LocalInvokeResolutionError(`Lambda '${logicalId}' in ${stackName} has an Fn::Join Code.ImageUri that cdkd local invoke cannot resolve${pseudoParameters ? " (likely ${AWS::AccountId}, which cdkd cannot derive without --from-state or STS)" : ` (cdkd could not derive AWS pseudo parameters because stack.region was undefined)`}. Workarounds: deploy first and run with --from-state, or pin a fully-literal public image URI.`);
42560
42610
  }
42561
42611
  }
42562
42612
  }
@@ -54691,7 +54741,7 @@ function resolveLambdaByLogicalId(logicalId, stacks) {
54691
54741
  const memoryMb = typeof props["MemorySize"] === "number" ? props["MemorySize"] : 128;
54692
54742
  const timeoutSec = typeof props["Timeout"] === "number" ? props["Timeout"] : 3;
54693
54743
  const code = props["Code"] ?? {};
54694
- const imageUri = extractImageUri(code["ImageUri"], logicalId, stack.stackName, stack.template.Resources ?? {});
54744
+ const imageUri = extractImageUri(code["ImageUri"], logicalId, stack.stackName, stack.template.Resources ?? {}, stack.region);
54695
54745
  if (imageUri !== void 0) return resolveImageLambda({
54696
54746
  stack,
54697
54747
  logicalId,
@@ -54735,29 +54785,24 @@ function resolveLambdaByLogicalId(logicalId, stacks) {
54735
54785
  * `lambda.DockerImageCode.fromImageAsset`), and `Fn::Join` (the
54736
54786
  * canonical shape for `lambda.DockerImageCode.fromImageAsset` in
54737
54787
  * CDK 2.x, which emits a `Fn::Join` over the literal bootstrap ECR
54738
- * URI with `${AWS::URLSuffix}` — issue #627).
54788
+ * URI with `${AWS::URLSuffix}` — issues #627 + #637).
54739
54789
  *
54740
54790
  * The `Fn::Join` arm routes through the shared
54741
54791
  * `tryResolveImageFnJoin` helper (`src/local/intrinsic-image.ts`) used
54742
- * by `cdkd local invoke`. Like the sibling `lambda-resolver.ts`, we
54743
- * pass `undefined` for the `ImageResolutionContext` start-api
54744
- * doesn't load cdkd state up front, so same-stack ECR refs surface
54745
- * as `needs-state` and pseudo-parameter-only shapes (`Ref:
54746
- * AWS::URLSuffix`) surface as `not-applicable`. Both cases throw a
54747
- * clear error that names the actual root cause instead of falling
54748
- * through to the ZIP branch's misleading "no Runtime" hard error.
54749
- *
54750
- * Pseudo-parameter substitution (`${AWS::URLSuffix}` → `amazonaws.com`)
54751
- * is deliberately not implemented here — `lambda-resolver.ts` (the
54752
- * canonical sibling) also defers it, and shipping one-sided support
54753
- * would surprise users. Tracked separately as the issue's optional
54754
- * follow-up.
54792
+ * by `cdkd local invoke`. When the synth template recorded a deploy
54793
+ * region (`stack.region`), we derive `{ urlSuffix, partition, region }`
54794
+ * via `derivePseudoParametersFromRegion` and pass it as the resolver's
54795
+ * `pseudoParameters` block so the canonical `${AWS::URLSuffix}` shape
54796
+ * resolves cleanly (issue #637). Same-stack ECR refs still surface as
54797
+ * `needs-state` (those require `--from-state`); a Join that references
54798
+ * `${AWS::AccountId}` without state still surfaces as `not-applicable`
54799
+ * with a more specific error message naming the missing parameter.
54755
54800
  *
54756
54801
  * Returns `undefined` when the field is absent or non-recognized,
54757
54802
  * which routes the caller to the ZIP branch (with its existing
54758
54803
  * "no Runtime / no Handler" validations).
54759
54804
  */
54760
- function extractImageUri(value, logicalId, stackName, resources) {
54805
+ function extractImageUri(value, logicalId, stackName, resources, region) {
54761
54806
  if (typeof value === "string" && value.length > 0) return value;
54762
54807
  if (value && typeof value === "object" && !Array.isArray(value)) {
54763
54808
  const obj = value;
@@ -54765,11 +54810,12 @@ function extractImageUri(value, logicalId, stackName, resources) {
54765
54810
  if (typeof sub === "string" && sub.length > 0) return sub;
54766
54811
  if (Array.isArray(sub) && typeof sub[0] === "string") return sub[0];
54767
54812
  if ("Fn::Join" in obj) {
54768
- const joinResolved = tryResolveImageFnJoin(value, resources, void 0);
54813
+ const pseudoParameters = derivePseudoParametersFromRegion(region);
54814
+ const joinResolved = tryResolveImageFnJoin(value, resources, pseudoParameters ? { pseudoParameters } : void 0);
54769
54815
  if (joinResolved.kind === "resolved") return joinResolved.uri;
54770
54816
  if (joinResolved.kind === "needs-state") throw new Error(`Lambda '${logicalId}' in ${stackName} references same-stack ECR repository '${joinResolved.repoLogicalId}' via Fn::Join. cdkd local start-api cannot resolve the repository URI without state — deploy the stack first (so cdkd records the repository physical id), rebuild via lambda.DockerImageCode.fromImageAsset, or pin a public image.`);
54771
54817
  if (joinResolved.kind === "unsupported-join") throw new Error(`Lambda '${logicalId}' in ${stackName} has an unsupported Fn::Join Code.ImageUri shape: ${joinResolved.reason}. cdkd local start-api recognizes the canonical CDK 2.x lambda.DockerImageCode.fromEcr Fn::Join shape (delimiter "" with nested Fn::Select/Fn::Split over an ECR Repository Arn GetAtt + Ref to the repo).`);
54772
- throw new Error(`Lambda '${logicalId}' in ${stackName} has an Fn::Join Code.ImageUri that cdkd local start-api cannot resolve. The shape likely references AWS pseudo parameters (e.g. \${AWS::URLSuffix}) the canonical CDK 2.x lambda.DockerImageCode.fromImageAsset synthesized shape. Workarounds: pin a fully-literal public image URI, or wait for the follow-up that substitutes \${AWS::URLSuffix} against the current region.`);
54818
+ throw new Error(`Lambda '${logicalId}' in ${stackName} has an Fn::Join Code.ImageUri that cdkd local start-api cannot resolve${pseudoParameters ? " (likely ${AWS::AccountId}, which cdkd cannot derive without --from-state or STS)" : ` (cdkd could not derive AWS pseudo parameters because stack.region was undefined)`}. Workarounds: deploy first and run with --from-state, or pin a fully-literal public image URI.`);
54773
54819
  }
54774
54820
  }
54775
54821
  }
@@ -59598,7 +59644,7 @@ function reorderArgs(argv) {
59598
59644
  */
59599
59645
  async function main() {
59600
59646
  const program = new Command();
59601
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.161.0");
59647
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.161.1");
59602
59648
  program.addCommand(createBootstrapCommand());
59603
59649
  program.addCommand(createSynthCommand());
59604
59650
  program.addCommand(createListCommand());