Add lstk sam command#312
Open
peter-smith-phd wants to merge 2 commits into
Open
Conversation
Add `lstk sam`, proxying the AWS SAM CLI against LocalStack — a first-party replacement for samlocal/aws-sam-cli-local (no install needed). It uses the lstk cdk env-var mechanism with the Terraform account model. - Points sam at LocalStack via AWS_ENDPOINT_URL only (SAM's botocore uses path-style S3 on a localhost endpoint, so no S3-specific endpoint is set); provides mock credentials and strips ambient AWS config. - Supports leading --region and --account (LocalStack derives the account from AWS_ACCESS_KEY_ID); writes the region to both AWS_REGION and AWS_DEFAULT_REGION since SAM reads the latter. - Gates AWS-contacting subcommands on a running emulator; runs offline ones (docs, init, build, validate, local, pipeline) without one. - Requires AWS SAM CLI 1.95.0+ (older versions ignore AWS_ENDPOINT_URL and would silently target real AWS). Known limitations vs samlocal: image/container-based Lambda (ECR) deploys and nested CloudFormation stacks are unsupported (they need in-process SAM patches a subprocess wrapper cannot apply). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The ubuntu-latest runner image happens to ship aws-sam-cli (1.161.1), so the `lstk sam` e2e tests pass today — but relying on that is fragile: if a future image drops it, requireSAM() would silently skip the tests and we'd lose all SAM e2e coverage with no signal. Install it explicitly via aws-actions/setup-sam on the Linux shards, mirroring the existing Terraform/OpenTofu/CDK install steps. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
aeca4ee to
b9b81ac
Compare
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 sam, proxying the AWS SAM CLI against LocalStack — a first-party replacement forsamlocal/aws-sam-cli-local(no extra install needed). This implementation is based on the work done forlstk terraformandlstk cdk.Closes DPX-506
What it does
samsubprocess at LocalStack viaAWS_ENDPOINT_URLonly — SAM's botocore auto-selects path-style S3 on alocalhostendpoint, so no S3-specific endpoint is set.AWS_PROFILE,AWS_DEFAULT_PROFILE,AWS_SESSION_TOKEN) that could accidentally causesamto contact real AWS.--regionand--account.samsubcommands to have a running AWS emulator, whereas offline ones (docs,init,build,validate,local,pipeline) don't require an emulator.1.95.0+. Older versions ignoreAWS_ENDPOINT_URLand would silently target real AWS).PATH, overridable viaLSTK_SAM_CMD.Known limitations vs samlocal
samlocalis a Python wrapper that monkeypatches SAM in-process;lstk samis a subprocess wrapper written in Go, so twosamlocalbehaviors are out of reach and not supported (usesamlocalfor them): 1) image/container-based Lambda (ECR) deploys and 2) nested CloudFormation stack template export. These are documented in the help text and tracked as open questions in the design doc.Layout
internal/iac/sam/cli/(env.go,defaults.go,version.go,exec.go) — mirrorsinternal/iac/cdk/cli/.cmd/sam.go, registered incmd/root.go; reusescmd/iac.gohelpers.openspec/changes/add-samlocal-command/.CLAUDE.md.Testing
sambinary (arg forwarding, env injection, version gate, missing binary,--account, offline gating, emulator gating).sam_e2e_test.go) against a realsamtalking to LocalStack. These exercise the full path, with no test mocks.🤖 Generated with Claude Code