0

We AWS AppConfig to manage our feature flag, I am trying to follow this doc: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-appconfig/index.html

but documentation is not so clear, can anyone help me with fetching feature flags in my angular app.

Suraj Kumar
  • 281
  • 6
  • 13
  • What have you tried and what is not working? – Dino Sep 30 '22 at 10:18
  • @Dino basically I just want to fetch the flags but the documentation does not clearly mention how should I pass application id , profile id etc (acceptable properties of params). – Suraj Kumar Sep 30 '22 at 10:22
  • Have you checked ```AppConfigClient``` ? https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-appconfig/src/AppConfigClient.ts You can see how to pass credentials there – Dino Sep 30 '22 at 10:49

1 Answers1

0

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/

ToDevAndBeyond
  • 1,120
  • 16
  • 24