Repository navigation
fix: run awslocal against the gateway's container-side address - #138
Merged
joe4dev merged 2 commits intoNov 20, 2026
Merged
Conversation
localstack-aws-client and the deployer's create-stack/delete-stack run awslocal inside the LocalStack container. awslocal derives its endpoint from LOCALSTACK_HOST, which names the host-side address, unless AWS_ENDPOINT_URL is set. With the gateway published on another host port (-p 4700:4566, LOCALSTACK_HOST=localhost.localstack.cloud:4700) or moved by GATEWAY_LISTEN, awslocal called a port nothing listens on inside the container. Each awslocal exec now gets AWS_ENDPOINT_URL=http://localhost:<port>, where the port is the first GATEWAY_LISTEN entry of the container's environment (LOCALSTACK_GATEWAY_LISTEN first, default 4566). Only the exec's environment changes; the container keeps its LOCALSTACK_HOST, so URLs LocalStack returns (SQS queue URLs) still name the host side. The awslocal-in-container pattern itself stays a known deviation (target: lstk aws, DEVX-1330); this only fixes its endpoint. Tests: unit tests for the endpoint derivation, handler tests for both tools, and tests/mcp/aws-client-ports.spec.mjs, which runs the aws-client and the deployer against LocalStack on the default port, a remapped host port and a custom GATEWAY_LISTEN. It runs in test:mcp:tools with one worker, so its default case does not race tools.spec.mjs for port 4566. Fixes DEVX-1338 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e caller 118299f pointed every in-container awslocal at the container-side gateway, so `s3 presign` returned http://localhost:<container port>/..., which the host cannot reach. Commands that sign a URL or token locally and print it without calling the gateway (s3 presign, rds generate-db-auth-token, eks get-token, dsql generate-db-connect-*) now get no AWS_ENDPOINT_URL, so awslocal uses LOCALSTACK_HOST as before. The decision lives in awslocal-endpoint.logic.ts (buildsClientUrl), and those commands skip the container inspect. The deployer now removes its temporary template in a finally block, so it no longer stays in the container when the create-stack exec throws. Tests: - unit: URL-building commands with and without global options, and look-alikes that call the gateway - handler tests run analytics and the preflights for real (PostHog and the gateway health probe mocked) and cover presign, a failing container inspect, LocalStack not running, create-stack and delete-stack failures, a missing stackName, the template cleanup, and a container auth token that must not reach the exec env, the response or analytics - aws-client-ports.spec.mjs: every case uses a free host port (the default case keeps the in-container defaults), ports are picked when a case runs, and the mapped and GATEWAY_LISTEN cases check that a presigned URL names the host port and can be fetched from the host Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Good-to-know: The localstack container resolves This shouldn't be an issue given this PR uses This PR is anyway only a quickfix |
joe4dev
marked this pull request as ready for review
November 20, 2026 09:22
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.
Motivation
localstack-aws-clientand the deployer's CloudFormation actions runawslocalinside the LocalStack container.awslocaltakes its endpoint from the container'sLOCALSTACK_HOST, which names the host-side address. When the gateway is published on another host port (-p 4700:4566withLOCALSTACK_HOST=localhost.localstack.cloud:4700), orGATEWAY_LISTENmoves it inside the container,awslocalcalls a port nothing listens on, and every command fails with "Could not connect to the endpoint URL". The agentic IAM eval hit this because it runs LocalStack on a free port.Solution
awslocalexec getsAWS_ENDPOINT_URL=http://localhost:<port>. The port is the firstGATEWAY_LISTENentry from the container's environment, parsed the way LocalStack does (LOCALSTACK_GATEWAY_LISTENwins, a host-only entry means 4566, IPv6 brackets). The default is 4566. The pure logic lives insrc/lib/aws/awslocal-endpoint.logic.ts, andsrc/lib/aws/awslocal.tsruns the exec.LOCALSTACK_HOST.awslocal's own endpoint, so the URL stays reachable from the host. These ares3 presign,rds generate-db-auth-tokenandeks get-token; thedsqltoken commands are listed for newer CLIs.finally.GATEWAY_LISTEN=:0(a random port) can't be learned from the environment and falls back to 4566.Running
awslocalin the container is still a known deviation (target:lstk aws, #137). This PR fixes only its endpoint, and the call now lives in one helper,src/lib/aws/awslocal.ts, which the deviation rows should name. Once #137 lands, the new integration spec should keep running against thelstk awspath.Testing
:4566,:443, a mapped host port, a customGATEWAY_LISTEN, IPv6, host-only entries, prefix precedence, invalid values) and the URL-building command list, with global options and look-alikes.stackName, template cleanup, and a fake token in the container's env that must reach neither the exec, the response nor analytics.tests/mcp/aws-client-ports.spec.mjs: three real LocalStack containers on free host ports (default in-container config, a mapped host port,GATEWAY_LISTEN). Each case runs SQS calls and a CloudFormation create-stack and delete-stack through the tools, checks that the queue URL names the host port, and, for the mapped cases, fetches ans3 presignURL from the host. It never publishes 4566. Before the fix, the two non-default cases failed with "Could not connect to the endpoint URL". The presign check needslocalhost.localstack.cloudto resolve to 127.0.0.1, which some DNS-rebinding-protected resolvers block.yarn build,yarn test(503 tests),tsc --noEmitand prettier on the changed files pass.test:mcp:toolsnow includes the new spec, with one worker.Adversarial review
Two rounds. The first found a presign regression, a way for the test to capture a host LocalStack's 127.0.0.1:4566 on macOS, and missing handler tests; all are fixed. The second round passed. Tool descriptions and schemas are unchanged, so no model eval is needed.
Related
Fixes DEVX-1338. Related: #137 (DEVX-1330).
🤖 Generated with Claude Code