Skip to content

LOCALSTACK_HOST environment variable mismatch with container port prevents connectivity #24

@mity1982

Description

@mity1982

🐛 Bug Description

What happened?
When the connection string is produced, it includes the LocalStack URL as visible from the host machine (e.g., localhost:4567). However, inside the container, only port 4566 is accessible. If the connection string uses a different port (like 4567), components inside the container such as awslocal or health checks cannot connect to LocalStack.

The environment variable LOCALSTACK_HOST is injected/reused in the container and in health checks for connectivity. In my setup, I pin LocalStack's host port to 4567 by setting the container's Port configuration. This results in LOCALSTACK_HOST=localhost:4567, but it should be localhost:4566 for internal container connections.

See the relevant code for context:

resourceBuilder.WithEnvironment("LOCALSTACK_HOST", $"{localStackUrl.Host}:{localStackUrl.Port.ToString(CultureInfo.InvariantCulture)}");

What did you expect to happen?
LOCALSTACK_HOST inside the container should always reference localhost:4566, regardless of the externally pinned host port. This ensures connectivity for awslocal and health checks.

🔄 Steps to Reproduce

  1. Configure LocalStack container with Port=4567 (or any port != 4566).
  2. Check injected LOCALSTACK_HOST environment variable inside container.
  3. Attempt to use awslocal or health checks within the container.
  4. Observe failed connectivity.

Minimal code example:

var builder = DistributedApplication.CreateBuilder(args);
var localstack = builder.AddLocalStack(configureContainer: options => {
    options.Port = 4567;
});
// Components relying on LOCALSTACK_HOST inside container fail
builder.Build().Run();

📋 Environment Information

.NET Aspire Information:

  • Aspire Version: 13

LocalStack Information:

  • LocalStack Image: 4.13.1

.NET Information:

  • .NET Version: 8

Aspire Configuration (Optional):

{
  "LocalStack": {
    "UseLocalStack": true,
  }
}

Error Messages/Stack Traces:

Connection failed: awslocal could not reach localhost:4567 from inside container
Health check failed inside container

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds reviewFurther consideration needed

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions