Read time: 3 minutes
Last edited: Jan 05, 2022
This topic explains how to enable offline mode for the Relay Proxy.
Enabling offline mode on the Relay Proxy lets you run the Relay Proxy without ever connecting it to LaunchDarkly. Instead of retrieving flag and segment values from LaunchDarkly's servers, the Relay Proxy gets them from files located on your local host or filesystem.
This allows you to run the Relay Proxy in a highly secure system, such as a FedRAMP-compliant system. By using offline mode, you can secure the Relay Proxy away from any external touchpoints.
When the Relay Proxy is in offline mode, it does not send events to LaunchDarkly, and event-driven app features do not indicate new activity. For example, flag statuses and insights do not update to reflect evaluations from an offline Relay Proxy.
You should not use a persistent feature store between the Relay Proxy and your application in offline mode.
Enabling offline mode is a two-step process. These steps appear in detail below.
- Create a Relay Proxy configuration in the Relay Proxy section of the Account Settings page and save its unique key.
- Configure your Relay Proxy instance to use the unique key from the prior step. You may do so either as a property in your Relay Proxy configuration file or as an environment variable.
When you create a new Relay Proxy, LaunchDarkly assigns a unique key to it. You must save the key immediately after you create the Relay Proxy, because the key is only viewable on creation.
Here's how to create a Relay Proxy configuration in the LaunchDarkly UI:
- Navigate to the Account Settings page and click into the Relay Proxy tab:
- Click Create configuration. The Relay Proxy configuration screen appears.
- Give the Relay Proxy a human-readable Name.
- Choose a Rule from the dropdown. This rule determines what content the Relay Proxy receives.
- All projects and environments sends changes about all projects and environments to the Relay Proxy.
- Inline policy allows you to specify which projects and environments you can track events for. To learn more, read Writing an inline policy.
- Click Save configuration. The Relay Proxy appears on the Relay Proxy tab of the Account Settings page with its key visible.
- Copy and save the key somewhere secure:
Next, you must download all your flag rules and segments locally and tell the Relay Proxy where to find them. You do this by associating the file containing your flag rules with the Relay Proxy in a configuration file or with an environment variable.
To get your flag rules and make them accessible to the Relay Proxy:
curl /relay/latest-all. This generates a file containing all your flag rules.
curl is below:
curl https://sdk.launchdarkly.com/relay/latest-all \-H "Authorization: rel-EXAMPLE-RELAY-PROXY-CONFIGURATION-KEY" \-o EXAMPLE-NAME-OF-OUTPUTTED-FILE.tar.gz
- Copy that file to your local host.
- The next step varies depending on whether you're using a configuration file or environment variables:
If you're using a configuration file, configure it to read the file you saved in step 2. In the file, specify an
OfflineModesection with the
fileDataSourcekey and a value of the file's path.
If you're using environment variables, specify the file with the
FILE_DATA_SOURCEenvironment variable.[OfflineMode]fileDataSource = "/path/to/file.tar.gz"
- Start the Relay Proxy.
From now on, the Relay Proxy will serve flag values based on the contents of the file you downloaded, not by contacting LaunchDarkly for updates.
After you configure the Relay Proxy to run in offline mode, you do not need to connect to a network to update flag rules. If your flag rules change, you can update the Relay Proxy by re-downloading the flag rules file and updating it on your filesystem.
To update the Relay Proxy in offline mode:
- Make a request to
https://sdk.launchdarkly.com/relay/latest-allto generate a file containing all your flag rules.
- Replace the existing file on the Relay Proxy's filesystem with the newly-generated file. The Relay Proxy will detect that the file has changed and will reload it.
The Relay Proxy automatically updates when it detects changes to your flag rules.