feat: Add lstk cdk proxy command#302
Draft
peter-smith-phd wants to merge 1 commit into
Draft
Conversation
Proxy AWS CDK against LocalStack by pointing the cdk subprocess at the resolved endpoint via AWS_ENDPOINT_URL/AWS_ENDPOINT_URL_S3 and stripping ambient AWS config, gating AWS-contacting subcommands on a running emulator and requiring cdk >= 2.177.0. Shared IaC command-boundary helpers move to cmd/iac.go so cdk and terraform no longer look terraform-owned, and e2e coverage adds a Lambda fromAsset stack that exercises S3 asset publishing through AWS_ENDPOINT_URL_S3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lstk cdk proxy command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
lstk cdk, a proxy that runs the real AWS CDK CLI against a running LocalStack emulator — mirroringlstk aws/lstk terraform. This replaces the existingcdklocalcommand, with the one caveat that using and endpoint ofhttp://127.0.01:4566orhttp://localhost:4566will NOT work correctly in some cases. A future solution is still required for this edge case.Implementation
See
openspec/changes/add-cdk-proxy-command/for the proposal, design, and spec.Endpoint via env vars (
internal/iac/cdk/cli/):BuildEnvsetsAWS_ENDPOINT_URL, the derivedAWS_ENDPOINT_URL_S3, mock creds, and region on the cdk subprocess.Safety — strip ambient AWS config:
AWS_PROFILE/AWS_DEFAULT_PROFILE/AWS_SESSION_TOKENare removed so a user's real credentials can't redirect a deploy at real AWS. This is the safety-critical core, mirroringcdklocal.Version floor 2.177.0: older CDK ignores the endpoint env vars and would silently hit real AWS, so
Runcheckscdk --versionup front and fails with an actionable error.Offline vs AWS-contacting gating: a fixed offline set (
synth/ls/init/…) runs without a running emulator; everything else is gated on the AWS emulator, reusing terraform's "wrong emulator" messaging.S3 endpoint addressing (
internal/endpoint): sharedS3Addressingderives thes3.-prefixed virtual-host endpoint for*.localstack.cloudhosts. Path-style on the127.0.0.1DNS-rebind fallback is a known limitation (CDK exposesforcePathStyleonly as a code-level arg, unreachable from a subprocess); lstk warns and the fix is out of scope for v1.Shared IaC helpers →
cmd/iac.go: the command-boundary helpers (--region/--accountparsing,requireRunningAWSEmulator,resolveAWSContainer, validation) moved out ofcmd/terraform.gointo a neutral file so cdk and terraform share them without one looking terraform-owned.Testing
cdk_cmd_test.go— stub-cdkintegration tests: arg/exit-code passthrough, env construction (set + stripped), emulator gating, version floor, flag handling,LSTK_CDK_CMD.cdk_e2e_test.go— real cdk + real LocalStack:synth(offline),bootstrap, single-bucketdeploy/destroy, and a LambdafromAssetround-trip that guarantees a real assetPutObjectacrossAWS_ENDPOINT_URL_S3(the bucket-only stack's small template may be inlined and never touch S3). Gated on Docker + real cdk + npm + auth token.Notes
cdk synth(asset resolves toS3Bucket: cdk-hnb659fds-assets-…); the full deploy round-trip runs in CI where Docker + token are present.Resolves DPX-505.
🤖 Generated with Claude Code