@go-to-k/cdkd 0.162.2 → 0.162.3

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
@@ -54737,6 +54737,7 @@ async function localStartApiCommand(target, options) {
54737
54737
  for (const [k, v] of direct) corsConfigByApiId.set(k, v);
54738
54738
  }
54739
54739
  const stateByStack = options.fromState || isCfnFlagPresent(options) ? await loadStateForRoutedStacks(targetStacks, routes, routesWithAuth, options) : /* @__PURE__ */ new Map();
54740
+ const profileCredentials = options.profile ? await resolveProfileCredentials(options.profile) : void 0;
54740
54741
  const lambdaIds = uniqueLambdaIds(routes, routesWithAuth, webSocketApis);
54741
54742
  const specs = /* @__PURE__ */ new Map();
54742
54743
  for (let i = 0; i < lambdaIds.length; i++) {
@@ -54753,7 +54754,8 @@ async function localStartApiCommand(target, options) {
54753
54754
  layerTmpDirs,
54754
54755
  stateByStack,
54755
54756
  skipPull: options.pull === false,
54756
- ...options.layerRoleArn !== void 0 && { layerRoleArn: options.layerRoleArn }
54757
+ ...options.layerRoleArn !== void 0 && { layerRoleArn: options.layerRoleArn },
54758
+ ...profileCredentials && { profileCredentials }
54757
54759
  });
54758
54760
  specs.set(logicalId, spec);
54759
54761
  }
@@ -55187,7 +55189,7 @@ function warnIamRoutes(routesWithAuth) {
55187
55189
  * missing, runtime not supported).
55188
55190
  */
55189
55191
  async function buildContainerSpec(args) {
55190
- const { logicalId, stacks, overrides, assumeRole, containerHost, debugPort, stsRegion, inlineTmpDirs, layerTmpDirs, stateByStack, skipPull, layerRoleArn } = args;
55192
+ const { logicalId, stacks, overrides, assumeRole, containerHost, debugPort, stsRegion, inlineTmpDirs, layerTmpDirs, stateByStack, skipPull, layerRoleArn, profileCredentials } = args;
55191
55193
  const lambda = resolveLambdaByLogicalId(logicalId, stacks);
55192
55194
  let codeDir;
55193
55195
  let optDir;
@@ -55233,7 +55235,15 @@ async function buildContainerSpec(args) {
55233
55235
  dockerEnv["AWS_SECRET_ACCESS_KEY"] = creds.secretAccessKey;
55234
55236
  dockerEnv["AWS_SESSION_TOKEN"] = creds.sessionToken;
55235
55237
  if (stsRegion) dockerEnv["AWS_REGION"] = stsRegion;
55236
- } else forwardAwsEnv$1(dockerEnv);
55238
+ } else {
55239
+ forwardAwsEnv$1(dockerEnv);
55240
+ if (profileCredentials) {
55241
+ dockerEnv["AWS_ACCESS_KEY_ID"] = profileCredentials.accessKeyId;
55242
+ dockerEnv["AWS_SECRET_ACCESS_KEY"] = profileCredentials.secretAccessKey;
55243
+ if (profileCredentials.sessionToken) dockerEnv["AWS_SESSION_TOKEN"] = profileCredentials.sessionToken;
55244
+ else delete dockerEnv["AWS_SESSION_TOKEN"];
55245
+ }
55246
+ }
55237
55247
  if (debugPort !== void 0) dockerEnv["NODE_OPTIONS"] = `--inspect-brk=0.0.0.0:${debugPort}`;
55238
55248
  const tmpfs = lambda.ephemeralStorageMb !== void 0 ? {
55239
55249
  target: "/tmp",
@@ -55596,6 +55606,54 @@ function forwardAwsEnv$1(env) {
55596
55606
  }
55597
55607
  }
55598
55608
  /**
55609
+ * Issue #654: resolve `--profile <p>` to a concrete credential set
55610
+ * for forwarding to Lambda containers.
55611
+ *
55612
+ * The dev's AWS credentials may live in any of:
55613
+ * - `~/.aws/sso/cache/*.json` (AWS IAM Identity Center / legacy SSO)
55614
+ * - `~/.aws/credentials` (regular long-lived access keys)
55615
+ * - `~/.aws/config` profiles with `role_arn` + `source_profile` (chained AssumeRole)
55616
+ * - `credential_process` external resolvers
55617
+ *
55618
+ * `forwardAwsEnv` only reads `process.env.AWS_*`, which is empty for
55619
+ * every shape except "user manually exported the env vars". The
55620
+ * Lambda container therefore boots without creds and the handler's
55621
+ * AWS SDK call fails with `Could not load credentials from any providers`.
55622
+ *
55623
+ * This helper constructs a transient `STSClient({ profile })` to drive
55624
+ * the SDK's default credential provider chain — same code path cdkd's
55625
+ * own CFn / CC API clients use when `--profile` is set, so SSO / IAM
55626
+ * Identity Center / role-assumption profiles all resolve the same way
55627
+ * they already do for cdkd's outbound calls. We then extract the
55628
+ * resolved `AwsCredentialIdentity` via `sts.config.credentials()` and
55629
+ * return the underlying `{ accessKeyId, secretAccessKey, sessionToken? }`
55630
+ * for env-var injection.
55631
+ *
55632
+ * Called ONCE at server boot; the resolved creds are reused for every
55633
+ * Lambda container's env overlay (when `--assume-role` is not set for
55634
+ * that Lambda — assume-role wins per the existing precedence). SSO
55635
+ * temp creds typically last 1h+, so a single resolve is fine for the
55636
+ * common dev session; long-running `--watch` sessions that outlive
55637
+ * the creds need a cdkd restart (deferred refresh out of scope for
55638
+ * v1, see issue #654).
55639
+ */
55640
+ async function resolveProfileCredentials(profile) {
55641
+ const { STSClient } = await import("@aws-sdk/client-sts");
55642
+ const sts = new STSClient({ profile });
55643
+ try {
55644
+ const credsProvider = sts.config.credentials;
55645
+ const creds = typeof credsProvider === "function" ? await credsProvider() : credsProvider;
55646
+ if (!creds || !creds.accessKeyId || !creds.secretAccessKey) throw new Error(`--profile '${profile}': credential provider chain resolved without usable credentials. Check \`aws sso login --profile ` + profile + "` for SSO profiles, or `~/.aws/credentials` / `~/.aws/config` for regular profiles.");
55647
+ return {
55648
+ accessKeyId: creds.accessKeyId,
55649
+ secretAccessKey: creds.secretAccessKey,
55650
+ ...creds.sessionToken && { sessionToken: creds.sessionToken }
55651
+ };
55652
+ } finally {
55653
+ sts.destroy();
55654
+ }
55655
+ }
55656
+ /**
55599
55657
  * Issue an STS AssumeRole and return temporary credentials. Mirrors
55600
55658
  * `cdkd local invoke`'s helper byte-for-byte; lifted here so the
55601
55659
  * start-api command stays self-contained.
@@ -60270,7 +60328,7 @@ function reorderArgs(argv) {
60270
60328
  */
60271
60329
  async function main() {
60272
60330
  const program = new Command();
60273
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.162.2");
60331
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.162.3");
60274
60332
  program.addCommand(createBootstrapCommand());
60275
60333
  program.addCommand(createSynthCommand());
60276
60334
  program.addCommand(createListCommand());