You could have the client initialize and get the feature flags when your application starts and then cache them in the client. Here is an example of how to use the AppConfigDataClient:
const {
AppConfigDataClient,
GetLatestConfigurationCommand,
StartConfigurationSessionCommand,
} = require("@aws-sdk/client-appconfigdata");
const client = new AppConfigDataClient({ region: "us-east-1" });
const getSession = new StartConfigurationSessionCommand({
//get these values from the provisioned appconfig instance
ApplicationIdentifier: "__placeholder__",
ConfigurationProfileIdentifier: "__placeholder__",
EnvironmentIdentifier: "__placeholder__",
});
async function test_appconfig() {
const sessionToken = await client.send(getSession);
const command = new GetLatestConfigurationCommand({
ConfigurationToken: sessionToken.InitialConfigurationToken,
});
//this gets the token and the latest configuration in binary, so it will need to be parsed to JSON
const response = await client.send(command);
console.log(response);
//converting binary to string
if (response.Configuration) {
let configJsonString = new TextDecoder().decode(response.Configuration);
const allFlags = JSON.parse(configJsonString);
console.log(allFlags);
}
}
test_appconfig();
Make sure you have NPM and node installed and Don't forget to install @aws-sdk/client-appconfigdata before running
npm install @aws-sdk/client-appconfigdata
You will also need to be authenticated with AWS. I simply signed into the AWS CLI before running, but there are other options.
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-your-credentials.html
Sources:
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/appconfigdata/