@go-to-k/cdkd 0.115.4 → 0.116.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.
- package/README.md +3 -4
- package/dist/cli.js +67 -25
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,15 +4,14 @@ Drop-in CDK CLI for existing CDK apps — faster deploys via AWS SDK instead of
|
|
|
4
4
|
|
|
5
5
|
- **Drop-in CDK compatible** — your existing CDK app code runs as-is.
|
|
6
6
|
- **Up to 15x faster deploys than the AWS CDK CLI (CloudFormation)**
|
|
7
|
-
- **
|
|
7
|
+
- **Local dev for CDK apps** — invoke Lambdas, serve API Gateway routes, and run ECS tasks directly from your CDK code, no `cdk synth → sam local` round-trip.
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|
|
|
11
11
|
**cdkd complements the AWS CDK CLI rather than replacing it.** Use cdkd in dev/test for rapid iteration and SAM-style local execution; use the AWS CDK CLI in production for full CloudFormation tooling. Bidirectional migration is supported — [import an existing CloudFormation stack](#importing-existing-resources) into cdkd for iteration, or [export back to CloudFormation](#exporting-a-stack-back-to-cloudformation) when ready for production.
|
|
12
12
|
|
|
13
|
-
>
|
|
14
|
-
>
|
|
15
|
-
> An experimental project exploring direct SDK provisioning as an alternative to the AWS CDK CLI — **NOT a replacement** and **NOT suitable for production use**. Features are incomplete, APIs may change without notice, and bugs may affect your AWS infrastructure. Use at your own risk in development / testing environments only.
|
|
13
|
+
> [!IMPORTANT]
|
|
14
|
+
> cdkd is for dev/test workflows only — early in development, not yet production-ready.
|
|
16
15
|
|
|
17
16
|
## Features
|
|
18
17
|
|
package/dist/cli.js
CHANGED
|
@@ -43862,7 +43862,17 @@ async function localInvokeCommand(target, options) {
|
|
|
43862
43862
|
if (stateAudit && stateAudit.unresolved.some((u) => u.key === key)) continue;
|
|
43863
43863
|
logger.warn(`Environment variable ${key} contains a CloudFormation intrinsic and was dropped. Override it with --env-vars (e.g. {"${lambda.logicalId}":{"${key}":"<literal>"}}) or pass --from-state to recover deployed values.`);
|
|
43864
43864
|
}
|
|
43865
|
-
|
|
43865
|
+
let resolvedAssumeRoleArn;
|
|
43866
|
+
if (typeof options.assumeRole === "string") resolvedAssumeRoleArn = options.assumeRole;
|
|
43867
|
+
else if (options.assumeRole === true) if (!stateForRoleHint) logger.warn("--assume-role passed without an ARN, but no cdkd state was loaded. Pair it with --from-state, or pass the ARN explicitly: --assume-role <arn>. Falling back to the developer's shell credentials.");
|
|
43868
|
+
else {
|
|
43869
|
+
const arn = resolveExecutionRoleArnFromState(stateForRoleHint, lambda.logicalId);
|
|
43870
|
+
if (arn) {
|
|
43871
|
+
resolvedAssumeRoleArn = arn;
|
|
43872
|
+
logger.info(`--assume-role: auto-resolved execution role from cdkd state: ${arn}`);
|
|
43873
|
+
} else logger.warn(`--assume-role: could not resolve the execution role ARN from cdkd state for '${lambda.logicalId}'. Pass the ARN explicitly: --assume-role <arn>. Falling back to the developer's shell credentials.`);
|
|
43874
|
+
}
|
|
43875
|
+
else if (options.assumeRole === void 0 && options.fromState && stateForRoleHint) suggestAssumeRoleFromState(stateForRoleHint, lambda.logicalId);
|
|
43866
43876
|
const event = await readEvent(options);
|
|
43867
43877
|
const dockerEnv = {
|
|
43868
43878
|
AWS_LAMBDA_FUNCTION_NAME: lambda.logicalId,
|
|
@@ -43873,14 +43883,22 @@ async function localInvokeCommand(target, options) {
|
|
|
43873
43883
|
AWS_LAMBDA_LOG_STREAM_NAME: "local",
|
|
43874
43884
|
...envResult.resolved
|
|
43875
43885
|
};
|
|
43876
|
-
|
|
43886
|
+
let assumeSucceeded = false;
|
|
43887
|
+
if (resolvedAssumeRoleArn) {
|
|
43877
43888
|
const stsRegion = options.region ?? process.env["AWS_REGION"] ?? process.env["AWS_DEFAULT_REGION"];
|
|
43878
|
-
|
|
43879
|
-
|
|
43880
|
-
|
|
43881
|
-
|
|
43882
|
-
|
|
43883
|
-
|
|
43889
|
+
try {
|
|
43890
|
+
const creds = await assumeLambdaExecutionRole(resolvedAssumeRoleArn, stsRegion);
|
|
43891
|
+
dockerEnv["AWS_ACCESS_KEY_ID"] = creds.accessKeyId;
|
|
43892
|
+
dockerEnv["AWS_SECRET_ACCESS_KEY"] = creds.secretAccessKey;
|
|
43893
|
+
dockerEnv["AWS_SESSION_TOKEN"] = creds.sessionToken;
|
|
43894
|
+
if (stsRegion) dockerEnv["AWS_REGION"] = stsRegion;
|
|
43895
|
+
assumeSucceeded = true;
|
|
43896
|
+
} catch (err) {
|
|
43897
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
43898
|
+
logger.warn(`--assume-role: STS AssumeRole(${resolvedAssumeRoleArn}) failed: ${reason}. Falling back to the developer's shell credentials.`);
|
|
43899
|
+
}
|
|
43900
|
+
}
|
|
43901
|
+
if (!assumeSucceeded) forwardAwsEnv(dockerEnv);
|
|
43884
43902
|
let debugPort;
|
|
43885
43903
|
if (options.debugPort) {
|
|
43886
43904
|
debugPort = Number(options.debugPort);
|
|
@@ -44171,11 +44189,10 @@ async function readStdin() {
|
|
|
44171
44189
|
/**
|
|
44172
44190
|
* Assume the Lambda execution role and return temporary credentials.
|
|
44173
44191
|
*
|
|
44174
|
-
*
|
|
44175
|
-
*
|
|
44176
|
-
*
|
|
44177
|
-
*
|
|
44178
|
-
* the user supplies the ARN explicitly.
|
|
44192
|
+
* Closes the "developer has admin creds, the deployed function has narrow
|
|
44193
|
+
* ones" skew that SAM users routinely hit. Off by default; opt-in via
|
|
44194
|
+
* `--assume-role <arn>` (explicit) or `--assume-role` (bare, auto-resolved
|
|
44195
|
+
* from cdkd state via `resolveExecutionRoleArnFromState`).
|
|
44179
44196
|
*
|
|
44180
44197
|
* Mirrors the env-var-write pattern from `applyRoleArnIfSet` in
|
|
44181
44198
|
* `src/utils/role-arn.ts` but writes the temp creds onto the container's
|
|
@@ -44250,26 +44267,51 @@ function materializeInlineCode(handler, source, fileExtension) {
|
|
|
44250
44267
|
return dir;
|
|
44251
44268
|
}
|
|
44252
44269
|
/**
|
|
44253
|
-
* When `--from-state` is set but `--assume-role`
|
|
44254
|
-
* deployed execution role ARN once as a hint.
|
|
44255
|
-
*
|
|
44256
|
-
*
|
|
44270
|
+
* When `--from-state` is set but `--assume-role` was NOT passed (not even
|
|
44271
|
+
* bare), log the function's deployed execution role ARN once as a hint.
|
|
44272
|
+
* This is the pre-(#442) behavior — kept for backward compatibility with
|
|
44273
|
+
* users who don't want auto-assume. The bare-`--assume-role` path opts
|
|
44274
|
+
* in to actually assuming the resolved ARN; this hint path stays
|
|
44275
|
+
* informational only.
|
|
44257
44276
|
*/
|
|
44258
44277
|
function suggestAssumeRoleFromState(state, logicalId) {
|
|
44259
44278
|
const logger = getLogger();
|
|
44279
|
+
const roleArn = resolveExecutionRoleArnFromState(state, logicalId);
|
|
44280
|
+
if (roleArn) logger.info(`Hint: the deployed function uses execution role ${roleArn}. Re-run with --assume-role to invoke under the deployed function's narrow permissions.`);
|
|
44281
|
+
}
|
|
44282
|
+
/**
|
|
44283
|
+
* Resolve the execution-role ARN for a Lambda from cdkd state. Used by
|
|
44284
|
+
* both the `--assume-role` auto-resolve path and the legacy hint path.
|
|
44285
|
+
*
|
|
44286
|
+
* Resolution rules (mirrors the v1 scope spelled out in (#442)):
|
|
44287
|
+
*
|
|
44288
|
+
* - Literal-string `Role` starting with `arn:` → returned verbatim.
|
|
44289
|
+
* - `{ Fn::GetAtt: [<RoleId>, 'Arn'] }` or `{ Ref: <RoleId> }` → looked up
|
|
44290
|
+
* against the sibling IAM Role resource's `attributes.Arn` (recorded
|
|
44291
|
+
* at deploy time by `IAMRoleProvider.create` / drift refresh).
|
|
44292
|
+
* - Any other shape (`Fn::Sub` / `Fn::Join` / cross-stack imports) → not
|
|
44293
|
+
* resolved in v1; the caller surfaces a warn and falls back to dev
|
|
44294
|
+
* creds. Once real CDK apps emit those shapes for `Role` we can
|
|
44295
|
+
* extend the resolver per `feedback_verify_cdk_synth_shape_before_resolver.md`.
|
|
44296
|
+
*
|
|
44297
|
+
* Returns `undefined` when state has no entry for the Lambda, the `Role`
|
|
44298
|
+
* is missing entirely, the referenced sibling has no `Arn` attribute
|
|
44299
|
+
* captured, or the shape is one we don't try to resolve.
|
|
44300
|
+
*
|
|
44301
|
+
* Exported for unit testing.
|
|
44302
|
+
*/
|
|
44303
|
+
function resolveExecutionRoleArnFromState(state, logicalId) {
|
|
44260
44304
|
const lambda = state.resources[logicalId];
|
|
44261
|
-
if (!lambda) return;
|
|
44305
|
+
if (!lambda) return void 0;
|
|
44262
44306
|
const roleRef = lambda.properties?.["Role"] ?? lambda.observedProperties?.["Role"];
|
|
44263
|
-
|
|
44264
|
-
if (typeof roleRef === "
|
|
44265
|
-
else if (typeof roleRef === "object" && roleRef !== null) {
|
|
44307
|
+
if (typeof roleRef === "string" && roleRef.startsWith("arn:")) return roleRef;
|
|
44308
|
+
if (typeof roleRef === "object" && roleRef !== null) {
|
|
44266
44309
|
const refLogicalId = pickReferencedLogicalId(roleRef);
|
|
44267
44310
|
if (refLogicalId) {
|
|
44268
44311
|
const cached = state.resources[refLogicalId]?.attributes?.["Arn"];
|
|
44269
|
-
if (typeof cached === "string" && cached.startsWith("arn:"))
|
|
44312
|
+
if (typeof cached === "string" && cached.startsWith("arn:")) return cached;
|
|
44270
44313
|
}
|
|
44271
44314
|
}
|
|
44272
|
-
if (roleArn) logger.info(`Hint: the deployed function uses execution role ${roleArn}. Re-run with --assume-role <that-arn> to invoke under the deployed function's narrow permissions.`);
|
|
44273
44315
|
}
|
|
44274
44316
|
/**
|
|
44275
44317
|
* Walk a single-key intrinsic and return the referenced logical ID, or
|
|
@@ -44293,7 +44335,7 @@ function pickReferencedLogicalId(intrinsic) {
|
|
|
44293
44335
|
*/
|
|
44294
44336
|
function createLocalCommand() {
|
|
44295
44337
|
const local = new Command("local").description("Local execution of Lambda functions (RIE) and ECS task definitions (Docker required)");
|
|
44296
|
-
const invoke = new Command("invoke").description("Run a Lambda function locally in a Docker container (RIE-backed). Target accepts a CDK display path (MyStack/MyApi/Handler) or stack-qualified logical ID (MyStack:MyApiHandler1234ABCD). Single-stack apps may omit the stack prefix.").argument("<target>", "CDK display path or stack-qualified logical ID of the Lambda to invoke").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("--no-pull", "Skip docker pull (use cached image) — no-op for IMAGE local-build path; `docker build` does not pull base layers by default")).addOption(new Option("--no-build", "Skip docker build on the IMAGE local-build path (use the previously-built tag). Requires the deterministic tag to already be in the local registry; errors with an actionable message when missing. No-op for ZIP Lambdas and the IMAGE ECR-pull path. Compatible with --no-pull.")).addOption(new Option("--debug-port <port>", "Node --inspect-brk port (default: off)")).addOption(new Option("--container-host <host>", "Host to bind the RIE port to").default("127.0.0.1")).addOption(new Option("--assume-role
|
|
44338
|
+
const invoke = new Command("invoke").description("Run a Lambda function locally in a Docker container (RIE-backed). Target accepts a CDK display path (MyStack/MyApi/Handler) or stack-qualified logical ID (MyStack:MyApiHandler1234ABCD). Single-stack apps may omit the stack prefix.").argument("<target>", "CDK display path or stack-qualified logical ID of the Lambda to invoke").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("--no-pull", "Skip docker pull (use cached image) — no-op for IMAGE local-build path; `docker build` does not pull base layers by default")).addOption(new Option("--no-build", "Skip docker build on the IMAGE local-build path (use the previously-built tag). Requires the deterministic tag to already be in the local registry; errors with an actionable message when missing. No-op for ZIP Lambdas and the IMAGE ECR-pull path. Compatible with --no-pull.")).addOption(new Option("--debug-port <port>", "Node --inspect-brk port (default: off)")).addOption(new Option("--container-host <host>", "Host to bind the RIE port to").default("127.0.0.1")).addOption(new Option("--assume-role [arn]", "Assume the Lambda's deployed execution role and forward STS-issued temp credentials to the container so the handler runs with the deployed function's narrow permissions (closes the \"developer admin / function narrow\" skew). Three forms: (1) `--assume-role <arn>` assumes the explicit ARN; (2) `--assume-role` (bare) auto-resolves the function's execution role ARN from cdkd state (requires --from-state); (3) `--no-assume-role` explicitly opts out (forces dev creds even with --from-state). Off by default — when omitted, the developer's shell credentials are forwarded unchanged (SAM-compatible default). STS failures degrade to a warn + dev-creds fallback.")).addOption(new Option("--from-state", "Read cdkd S3 state for the target stack and substitute Ref / Fn::GetAtt / Fn::Sub in env vars with the deployed physical IDs / attributes. Off by default — keep PR 1 warn-and-drop semantics; turn on for stacks already deployed via cdkd deploy.").default(false)).addOption(new Option("--stack-region <region>", "Region of the cdkd state record to read (used with --from-state when the same stack name has state in multiple regions).")).action(withErrorHandling(localInvokeCommand));
|
|
44297
44339
|
[
|
|
44298
44340
|
...commonOptions,
|
|
44299
44341
|
...appOptions,
|
|
@@ -45581,7 +45623,7 @@ function reorderArgs(argv) {
|
|
|
45581
45623
|
*/
|
|
45582
45624
|
async function main() {
|
|
45583
45625
|
const program = new Command();
|
|
45584
|
-
program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.
|
|
45626
|
+
program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.116.0");
|
|
45585
45627
|
program.addCommand(createBootstrapCommand());
|
|
45586
45628
|
program.addCommand(createSynthCommand());
|
|
45587
45629
|
program.addCommand(createListCommand());
|