fix(aws): honour AWS_ENDPOINT_URL for aws4fetch-based resources - #1405
Merged
Conversation
Adds an `awsEndpoint(service, region)` helper that resolves `AWS_ENDPOINT_URL_<SERVICE>` then `AWS_ENDPOINT_URL`, falling back to the default `https://<service>.<region>.amazonaws.com`. Wires it into the aws4fetch call sites that previously hardcoded the AWS host: - `callEC2Api` (EC2 resources: Vpc, Subnet, SecurityGroup, …) - `getAwsApiCaller` (generic XML-API caller) - `CloudControlClient.fetch` (every `aws/control/*` resource) This unblocks LocalStack / moto / motoserver workflows and matches the AWS SDK v3 / AWS CLI env-var convention so users don't have to learn a new variable. Also enables `forcePathStyle` on `S3Client` whenever an S3 endpoint override is in effect, since most emulators reject virtual-hosted-style addressing. Closes #1404
Drop the S3 forcePathStyle/S3StateStore changes and the helper's test suite — the S3 quirk is out of scope for this fix. All that remains is the one-liner `awsEndpoint()` helper and its three aws4fetch consumers (EC2 callEC2Api, CloudControlClient, getAwsApiCaller).
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
Fixes #1404 — aws4fetch-based AWS resources didn't pick up
AWS_ENDPOINT_URL/AWS_ENDPOINT_URL_<SERVICE>after the SDK→aws4fetch migration, which blocked LocalStack / moto / motoserver workflows.Adds an
awsEndpoint(service, region)helper inalchemy/src/aws/utils.ts:AWS_ENDPOINT_URL_<SERVICE>(e.g.AWS_ENDPOINT_URL_EC2) wins firstAWS_ENDPOINT_URLis the global fallbackhttps://<service>.<region>.amazonaws.com…and wires it into the three aws4fetch call sites that previously hardcoded the AWS host:
callEC2Api(EC2:Vpc,Subnet,SecurityGroup,SecurityGroupRule,RouteTable,Route,RouteTableAssociation,NatGateway,InternetGateway,InternetGatewayAttachment)CloudControlClient.fetch(everyaws/control/*resource)getAwsApiCaller(generic XML-API caller)Also flips
forcePathStyle: trueonS3Clientwhenever an S3 endpoint override is in effect, since most emulators reject virtual-hosted-style — same trick the AWS CLI uses.Usage
Test plan
bun vitest run ./alchemy/test/aws/endpoint.test.ts— 8 new unit tests covering precedence (service-specific > global > default), trailing-slash stripping, hyphen→underscore env-var normalisation, andhasAwsEndpointOverridedetectionbun tsc --noEmitclean acrossalchemy/bun formatcleanAWS_ENDPOINT_URL=http://localhost:4566at a running LocalStack and exerciseVpc, anaws/control/*resource, andBucketend-to-endGenerated by Claude Code