aws-cdk-local icon indicating copy to clipboard operation
aws-cdk-local copied to clipboard

Cannot Set AWS_ENDPOINT_URL_S3 Without DNS Mapping

Open ewx-mjanda opened this issue 8 months ago • 4 comments

For the use case where the localstack instance is on a remote server, the environment variables AWS_ENDPOINT_URL and AWS_ENDPOINT_URL_S3 must be set. It should be noted that this requirement appears to have been added when LOCALSTACK_HOSTNAME was deprecated. The problem with setting the AWS_ENDPOINT_URL_S3 variable is the additional requirement that the "server" be in the format of s3.servername.domain which will never resolve correctly without a DNS mapping.

aws-cdk-local version: 3.0.1

Error messages when trying to bootstrap the localstack environment (S3 upload errors):

XXXXXXStack: fail: getaddrinfo ENOTFOUND cdk-hnb659fds-assets-000000000000-us-east-1.s3.servername.domain

ewx-mjanda avatar Apr 25 '25 13:04 ewx-mjanda

Hi, thanks for posting this issue. You are right this is a problem that we have seen before. We are working on a solution.

Context: the problem is:

  • the CDK performs an S3 PutObject to upload the CFn template
  • this request (by default) is sent to <bucket>.s3.<$AWS_ENDPOINT_URL>/<key> so requires subdomains
  • if configuring "path style" addressing, it is still sent to s3.<$AWS_ENDPOINT_URL>/<bucket>/<key> which requires subdomains
  • we default to setting AWS_ENDPOINT_URL_S3 to enforce the subdomain is added, otherwise the request is directed to CloudFormation which cannot parse the template as an API request
  • when using localhost.localstack.cloud we allow subdomains, so this all works out of the box

This behaviour is hard-coded in the CDK, and since version 2.177 we cannot monkeypatch the package to support our own use cases, which is what we used to do.

One idea I've had is to start a proxy server which rewrites S3 requests to a format that LocalStack always supports (docs here), or to add another method of detecting this request, via a custom header or something. Unfortunately this is WIP, but I'll keep this issue updated.

simonrw avatar Apr 29 '25 14:04 simonrw

Hi, thanks @simonrw. We have the same issue. Do you possibly have any updates or an ETA?

"aws-cdk": "^2.193.0",
"aws-cdk-local": "^3.0.1",

Update

My problem got solved by using the static IP of the localstack service as described here.

amirkarimi avatar May 05 '25 18:05 amirkarimi

  • the CDK performs an S3 PutObject to upload the CFn template
  • this request (by default) is sent to .s3.<$AWS_ENDPOINT_URL>/ so requires subdomains
  • if configuring "path style" addressing, it is still sent to s3.<$AWS_ENDPOINT_URL>// which requires subdomains

@simonrw Is there an issue on https://github.com/aws/aws-cdk about this? It seems this issue can't be fixed in aws-cdk-local until aws-cdk respects s3ForcePathStyle?

cj-christoph-gysin avatar Aug 15 '25 06:08 cj-christoph-gysin

Hi, thanks @simonrw. We have the same issue. Do you possibly have any updates or an ETA?

"aws-cdk": "^2.193.0",
"aws-cdk-local": "^3.0.1",

Update

My problem got solved by using the static IP of the localstack service as described here.

Thanks @amirkarimi. This works perfect!

pascencio avatar Oct 01 '25 17:10 pascencio