@go-to-k/cdkd 0.281.27 → 0.281.28

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.
@@ -1054,6 +1054,25 @@ function resetAwsClients() {
1054
1054
  */
1055
1055
  const cache = /* @__PURE__ */ new Map();
1056
1056
  /**
1057
+ * Read an S3 client's resolved region without issuing a network call.
1058
+ *
1059
+ * Used to discover what the AWS SDK's own region chain (env vars, shared
1060
+ * config profile) picked for a client that was constructed WITHOUT an
1061
+ * explicit region. Never throws — an unresolvable chain (and a hand-rolled
1062
+ * test double with no `config`) both degrade to `undefined` so the caller
1063
+ * falls through to its own default.
1064
+ */
1065
+ async function readClientRegion(client) {
1066
+ try {
1067
+ const config = client.config;
1068
+ if (!config || typeof config.region !== "function") return void 0;
1069
+ const region = await config.region();
1070
+ return typeof region === "string" && region.length > 0 ? region : void 0;
1071
+ } catch {
1072
+ return;
1073
+ }
1074
+ }
1075
+ /**
1057
1076
  * Resolve the AWS region of an S3 bucket via `GetBucketLocation`.
1058
1077
  *
1059
1078
  * Why `GetBucketLocation` rather than `HeadBucket`:
@@ -1064,27 +1083,59 @@ const cache = /* @__PURE__ */ new Map();
1064
1083
  * `GetBucketLocation` is a GET with an XML body and is not subject to the
1065
1084
  * same SDK glitch.
1066
1085
  *
1067
- * Why a region-agnostic client (us-east-1):
1068
- * `GetBucketLocation` works against the global S3 endpoint regardless of
1069
- * the bucket's actual region, so we don't need to know the answer to ask
1070
- * the question.
1071
- *
1072
- * The result is cached per bucket name for the process lifetime — bucket
1073
- * regions never move, so the cache never needs invalidation.
1086
+ * Why the probe is NOT pinned to us-east-1 (issue
1087
+ * [#1763](https://github.com/go-to-k/cdkd/issues/1763)):
1088
+ * `GetBucketLocation` is answered by ANY regional S3 endpoint for any
1089
+ * bucket in the SAME PARTITION — measured 2026-08-13 against a real
1090
+ * eu-west-1 bucket, which resolved identically from us-east-1 / us-west-2 /
1091
+ * ap-northeast-1 / eu-west-1 clients so the probe never needs to know the
1092
+ * answer to ask the question. But it DOES have to reach the right
1093
+ * partition: a hardcoded `us-east-1` endpoint is unreachable from `aws-cn`
1094
+ * / `us-iso*`, so outside the commercial partition the probe could not run
1095
+ * at all, every call fell through to the commercial default, and every
1096
+ * consumer (the state backend, the lock manager, the exports index, the
1097
+ * custom-resource response path, `upload-cfn-template`) proceeded against
1098
+ * the wrong region. The probe endpoint is therefore taken from, in order:
1099
+ * `opts.region`, `opts.fallbackRegion`, the AWS SDK's own region chain
1100
+ * (env / shared config profile — the chain every other cdkd client
1101
+ * consults), and only then `us-east-1`. Commercial behavior is unchanged:
1102
+ * the resolved value is identical from any commercial endpoint, and a
1103
+ * caller with no region configured anywhere still probes `us-east-1`.
1104
+ *
1105
+ * A SUCCESSFUL result is cached per bucket name for the process lifetime —
1106
+ * bucket regions never move, so the cache never needs invalidation. A FAILED
1107
+ * probe is deliberately NOT cached (mirroring `write-only-properties.ts`):
1108
+ * the failure answer is a guess, and caching it let one transient error pin
1109
+ * every later caller in the process to the wrong region with no way to heal.
1074
1110
  *
1075
1111
  * @returns The bucket's region (e.g. `us-west-2`). An empty `LocationConstraint`
1076
- * in the response means `us-east-1` (S3 quirk). On any error, returns
1077
- * `opts.fallbackRegion` if provided, else `us-east-1`.
1112
+ * in the response means `us-east-1` (S3 quirk non-commercial partitions
1113
+ * always report their region explicitly). On any error, returns
1114
+ * `opts.fallbackRegion` if provided, else the region the probe was aimed at.
1078
1115
  */
1079
1116
  async function resolveBucketRegion(bucketName, opts = {}) {
1080
1117
  const cached = cache.get(bucketName);
1081
1118
  if (cached) return cached;
1119
+ let probeFailed = false;
1082
1120
  const promise = (async () => {
1083
- const client = new S3Client({
1084
- region: "us-east-1",
1121
+ const auth = {
1085
1122
  ...opts.profile && { profile: opts.profile },
1086
1123
  ...opts.credentials && { credentials: opts.credentials }
1124
+ };
1125
+ const explicitRegion = opts.region ?? opts.fallbackRegion;
1126
+ let client = new S3Client({
1127
+ ...explicitRegion && { region: explicitRegion },
1128
+ ...auth
1087
1129
  });
1130
+ let probeRegion = explicitRegion ?? await readClientRegion(client);
1131
+ if (!probeRegion) {
1132
+ client.destroy();
1133
+ probeRegion = "us-east-1";
1134
+ client = new S3Client({
1135
+ region: probeRegion,
1136
+ ...auth
1137
+ });
1138
+ }
1088
1139
  try {
1089
1140
  const { expectedOwnerParam } = await Promise.resolve().then(() => expected_bucket_owner_exports);
1090
1141
  return (await client.send(new GetBucketLocationCommand({
@@ -1092,13 +1143,16 @@ async function resolveBucketRegion(bucketName, opts = {}) {
1092
1143
  ...await expectedOwnerParam(client)
1093
1144
  }))).LocationConstraint || "us-east-1";
1094
1145
  } catch {
1095
- return opts.fallbackRegion ?? "us-east-1";
1146
+ probeFailed = true;
1147
+ return opts.fallbackRegion ?? probeRegion;
1096
1148
  } finally {
1097
1149
  client.destroy();
1098
1150
  }
1099
1151
  })();
1100
1152
  cache.set(bucketName, promise);
1101
- return promise;
1153
+ const region = await promise;
1154
+ if (probeFailed && cache.get(bucketName) === promise) cache.delete(bucketName);
1155
+ return region;
1102
1156
  }
1103
1157
  /**
1104
1158
  * Clear the per-bucket region cache. Used by tests to reset state between
@@ -13587,7 +13641,7 @@ var CloudControlProvider = class {
13587
13641
  if (context?.finalSnapshotIdentifier !== void 0) throw new ProvisioningError(`${logicalId} (${resourceType}) requires a final snapshot (DeletionPolicy: Snapshot), but the Cloud Control API delete route has no final-snapshot parameter. Re-run with --skip-final-snapshot after snapshotting manually, or retain the resource.`, resourceType, logicalId, physicalId);
13588
13642
  if (context?.removeProtection === true && resourceType === "AWS::AutoScaling::AutoScalingGroup") {
13589
13643
  this.logger.debug(`Delegating protected AutoScalingGroup ${logicalId} delete to the SDK ASGProvider (Cloud Control cannot force-delete a protected ASG)`);
13590
- const { ASGProvider } = await import("./asg-provider-CwcEOJx0.js").then((n) => n.n);
13644
+ const { ASGProvider } = await import("./asg-provider-CPA-dc1x.js").then((n) => n.n);
13591
13645
  await new ASGProvider().delete(logicalId, physicalId, resourceType, _properties, context);
13592
13646
  return;
13593
13647
  }
@@ -20504,7 +20558,7 @@ const FLUSH_INTERVAL_MS = 2e3;
20504
20558
  const FLUSH_EVENT_THRESHOLD = 50;
20505
20559
  /** Build-time cdkd version, with a dev fallback for non-built contexts. */
20506
20560
  function getCdkdVersion() {
20507
- return "0.281.27";
20561
+ return "0.281.28";
20508
20562
  }
20509
20563
  /**
20510
20564
  * Generate a time-sortable unique run id, e.g.
@@ -22673,4 +22727,4 @@ var DeployEngine = class {
22673
22727
 
22674
22728
  //#endregion
22675
22729
  export { configStringRefusal as $, MIGRATE_TMP_PREFIX as $t, green as A, SynthesisError as An, validateContainerRepoName as At, slowCcOperationTimeoutMs as B, getDefaultStateBucketName as Bt, MULTI_REGION_RECREATE_BLOCKED_TYPES as C, PartialFailureError as Cn, rewriteTemplateAssetReferences as Ct, bold as D, StackHasActiveImportsError as Dn, getBootstrapMarkerKey as Dt, formatResourceLine as E, ResourceUpdateNotSupportedError as En, ensureAssetStorage as Et, clearOnUpdateRemoval as F, __exportAll as Fn, runDockerStreaming as Ft, getAccountInfo as G, resolveSkipPrefix as Gt, isTerminationProtectionPropagationError as H, resolveApp as Ht, ProviderRegistry as I, AssetManifestLoader as It, normalizeAwsTagsToCfn as J, resolveUseCdkBootstrapAssets as Jt, refStateLookupFromResource as K, resolveStateBucketWithDefault as Kt, findActionableSilentDrops as L, getDockerImageBySourceHash as Lt, yellow as M, isCdkdError as Mn, formatDockerLoginError as Mt, IAMRoleProvider as N, normalizeAwsError as Nn, getDockerCmd as Nt, cyan as O, StackTerminationProtectionError as On, parseBootstrapMarker as Ot, collectInlinePolicyNamesManagedBySiblings as P, withErrorHandling as Pn, runDockerForeground as Pt, configBooleanRefusal as Q, CFN_TEMPLATE_URL_LIMIT as Qt, findSilentDropProperties as R, Synthesizer as Rt, extractDeploymentEventError as S, NestedStackChildDirectDestroyError as Sn, loadPublishableAssetManifest as St, renderStatefulReason as T, ResourceTimeoutError as Tn, BOOTSTRAP_MARKER_PREFIX as Tt, IntrinsicFunctionResolver as U, resolveAutoAssetStorage as Ut, disableInstanceApiTermination as V, getLegacyStateBucketName as Vt, cfnRefValueFromPhysicalId as W, resolveCaptureObservedState as Wt, assertRegionMatch as X, warnDeprecatedNoPrefixCliFlag as Xt, resolveExplicitPhysicalId as Y, stateBucketExistenceConfirmed as Yt, coerceCfnBoolean as Z, CFN_TEMPLATE_BODY_LIMIT as Zt, createPreDeleteFinalSnapshot as _, LocalInvokeBuildError as _n, AssetPublisher as _t, DeploymentEventsStore as a, processStackMessages as an, applyRoleArnIfSet as at, unsupportedFinalSnapshotError as b, LockError as bn, buildAssetRedirectMap as bt, replayFailedOperations as c, AwsClients as cn, withRetry as ct, IMPLICIT_DELETE_DEPENDENCIES as d, setAwsClients as dn, DagBuilder as dt, findLargeInlineResources as en, readConfigString as et, computeImplicitDeleteEdges as f, AssetError as fn, TemplateParser as ft, ccRoutedFinalSnapshotError as g, DeployCancelledError as gn, shouldRetainResource as gt, buildFinalSnapshotIdentifier as h, DependencyError as hn, rebuildClientForBucketRegion as ht, DeploymentEventsReader as i, AssemblyReader as in, requireConfigString as it, red as j, formatError as jn, buildDockerImage as jt, gray as k, StateError as kn, validateAssetBucketName as kt, replayRollback as l, getAwsClients as ln, isRetryableTransientError as lt, PRE_DELETE_SNAPSHOT_TYPES as m, ConfigError as mn, S3StateBackend as mt, DEFAULT_RESOURCE_WARN_AFTER_MS as n, expectedOwnerParam as nn, requireConfigArray as nt, planFailedOps as o, clearBucketRegionCache as on, DiffCalculator as ot, ATOMIC_FINAL_SNAPSHOT_TYPES as p, CdkdError as pn, LockManager as pt, WAFv2WebACLProvider as q, resolveStateBucketWithDefaultAndSource as qt, DeployEngine as r, derivePartitionAndUrlSuffix as rn, requireConfigObject as rt, planRollback as s, resolveBucketRegion as sn, describeTypeWithThrottleRetry as st, DEFAULT_RESOURCE_TIMEOUT_MS as t, uploadCfnTemplate as tn, replayWarn as tt, withResourceDeadline as u, resetAwsClients as un, isThrottlingError as ut, isFinalSnapshotError as v, LocalMigrateError as vn, stringifyValue as vt, isStatefulRecreateTargetSync as w, ProvisioningError as wn, AssetModeResolver as wt, makeCanonicalizePropertiesFn as x, MissingCdkCliError as xn, createAssetRedirectResolver as xt, refusesFinalSnapshot as y, LocalStartServiceError as yn, WorkGraph as yt, CloudControlProvider as z, synthesisStatusMessage as zt };
22676
- //# sourceMappingURL=deploy-engine-CP5fB_0I.js.map
22730
+ //# sourceMappingURL=deploy-engine-DnvhlIW5.js.map