Accessing a resource created by LocalStack
2 minute read
If you have created a resource using LocalStack, such as an OpenSearch cluster or RDS database, you may need to access it from your application. Typically, these resources are accessible through a URL or a hostname provided by LocalStack. While the environment variable
HOSTNAME_EXTERNAL can often control the returned hostname, this approach may only work for some cases. This guide will explore different scenarios and provide detailed instructions on accessing resources created by LocalStack under different scenarios.
NoteAn additional environment variable is available:
LOCALSTACK_HOSTNAME. It is primarily used for communication within LocalStack and should not be used. We are currently working on streamlining the configuration under different scenarios.
From your host
For example, suppose you have created an OpenSearch cluster using LocalStack and want to access it from the same computer. In such a case, you can set the
HOSTNAME_EXTERNAL environment variable to specify the desired hostname that will be returned. Check out the service-specific documentation for more details.
From a container LocalStack created
Check out our documentation while using the endpoint URL.
The Lambda service in LocalStack also supports the
HOSTNAME_FROM_LAMBDA environment variable, which can be handy if LocalStack is reachable through a specific hostname. Suppose you’re running LocalStack in a user-defined network using Docker, where the LocalStack container can be accessed from other containers in the network using its service name. In that case, you can set the
HOSTNAME_FROM_LAMBDA environment variable to this value to help resolve any issues with lambda functions accessing resources created by LocalStack.
From your container
Check out our documentation on using the endpoint URL.
From a separate host
LocalStack must listen to the address of the host, or
Check out our FAQ article on accessing LocalStack from another computer.