When you create an environment in FlexStack, we set up your network with Service Discovery enabled. There are two ways to use it:
- If you're communicating between services within the cluster (for example, between web services and private services) you can use proxy addresses. A service's proxy address can be found under the "Internal service URL" heading on a component overview page. In the example below, calling
http://ingest.flexstack.internal:8080
from another service within the cluster to hit the "ingest" service on port 8080.
- If you would like to call a service from outside the cluster, but within the private network (for example, from a serverless function) you may use the address
dns.[COMPONENT_NAME].[PROJECT_NAME]-[ENVIRONMENT_NAME].internal:[PORT]
to use DNS queries for discovery, ordns.ingest.[PROJECT_NAME]-[ENVIRONMENT_NAME].internal:8080
using the same example above. To select a specific or random healthy instance within the namespace, you can use the AWS CloudMap DiscoverInstances API. Here is an example using TypeScript. In this example, the ServiceName property would beingest
and the NamespaceName property would be[PROJECT_NAME]-[ENVIRONMENT_NAME].internal
.
How it works
The architecture for this is pretty straightforward. Every container service you create in FlexStack gets registered in AWS CloudMap and AWS ECS Service Connect. In the case of Service Connect, every port you expose in your service gets its own address in service connect at [PORT_NAME].[COMPONENT_NAME].[PROJECT_NAME]-[ENVIRONMENT_NAME].internal
.
You can programmatically access the discovery DNS namespace in your application using the FLEXSTACK_DISCOVERY_NAMESPACE
environment variable.