Skip to content

Accessing LocalStack via the endpoint URL

This documentation provides step-by-step guidance on how to access LocalStack services via the endpoint URL and troubleshoot common issues.

Code communicating with LocalStack via an endpoint

Suppose you have LocalStack installed on your machine and want to access it using the AWS CLI. To connect, you must expose port 4566 from your LocalStack instance and connect to localhost or a domain name that points to localhost. While the LocalStack CLI does this automatically, when running the Docker container directly or with docker compose, you must configure it manually. Check out the getting started documentation for more information.

You can also use the GATEWAY_LISTEN configuration variable to change the exposed port if necessary.

An ECS container communicating with LocalStack via an endpoint

Suppose your code is running inside an ECS container that LocalStack has created.

The LocalStack instance is available at the domain localhost.localstack.cloud. All subdomains of localhost.localstack.cloud also resolve to the LocalStack instance, e.g. API Gateway default URLs.

For LocalStack versions before 2.3.0 To enable access to the LocalStack instance, it’s advisable to start LocalStack in a user-defined network, and then set the MAIN_DOCKER_NETWORK environment variable to this network’s name. This allows the code running inside the container to access the LocalStack instance using its hostname. For example:

Terminal window
# create the network
docker network create my-network
# launch localstack
MAIN_DOCKER_NETWORK=my-network DOCKER_FLAGS="--network my-network" localstack start
# then your code can access localstack at its container name (by default: localstack-main)
aws --endpoint-url http://localstack-main:4566 s3api list-buckets

A docker container communicating with LocalStack via an endpoint

Suppose you’re accessing AWS resources such as S3 in LocalStack by running your application code in a container. Your application container should be configured to use LocalStack as its DNS server. Once this is done, the domain name localhost.localstack.cloud will resolve to the LocalStack container. All subdomains of localhost.localstack.cloud will also resolve to the LocalStack instance, e.g. API Gateway default URLs.

To configure your application container:

  • add a user-managed docker network;
  • either determine your LocalStack container IP, or configure your LocalStack container to have a fixed known IP address;
  • set the DNS server of your application container to the IP address of the LocalStack container.
Terminal window
# start localstack
localstack start -d --network ls
localstack wait
# get the ip address of the LocalStack container
docker inspect localstack-main | \
jq -r '.[0].NetworkSettings.Networks | to_entries | .[].value.IPAddress'
# prints 172.27.0.2
# run your application container
docker run --rm -it --dns 172.27.0.2 --network ls <arguments> <image name>

For LocalStack versions before 2.3.0 To facilitate access to LocalStack from within the container, it’s recommended to start LocalStack in a user-defined network and set the MAIN_DOCKER_NETWORK environment variable to the network’s name. Doing so enables the containerized code to connect to the LocalStack instance using its hostname. For instance:

Terminal window
# create the network
docker network create my-network
# launch localstack
DOCKER_FLAGS="--network my-network" localstack start
# launch your container
docker run --rm it --network my-network <image name>
# then your code can access localstack at its container name (by default: localstack-main)

LocalStack newer than version 2.3.0 supports wildcard DNS access by default. Please update your LocalStack container and see the instructions.

A separate host communicating with LocalStack via an endpoint

LocalStack must listen to the address of the host, or 0.0.0.0.

Terminal window
GATEWAY_LISTEN="0.0.0.0" localstack start

Check out our FAQ article on accessing LocalStack from another computer.