Retrieving basic and multi-variant feature flags
For feature flag configurations (configurations of type
AWS.AppConfig.FeatureFlags
), the Amazon AppConfig Agent enables you to retrieve a
single flag or a subset of flags in a configuration. Retrieving one or two flags is useful
if your use case only needs to use a few flags from the configuration profile. The following
examples use Python.
Note
The ability to call a single feature flag or a subset of flags in a configuration is only available in the Amazon AppConfig Agent version 2.0.45 and higher.
You can retrieve Amazon AppConfig configuration data from a local HTTP endpoint. To access a
specific flag or a list of flags, use the
?flag=
query parameter for an Amazon AppConfig
configuration profile.flag_name
To retrieve a single flag and its attributes
curl "http://localhost:2772/applications/
APPLICATION_NAME
/environments/ENVIRONMENT_NAME
/configurations/CONFIGURATION_NAME
?flag=FLAG_NAME
"
To retrieve multiple flags and their attributes
curl "http://localhost:2772/applications/
APPLICATION_NAME
/environments/ENVIRONMENT_NAME
/configurations/CONFIGURATION_NAME
?flag=FLAG_NAME_ONE
&FLAG_NAME_TWO
"
To retrieve feature flag variants based on caller context
The following Python examples show how to retrieve feature flag variants based on caller context. To best illustrate how to make these calls, this section uses sample calls based on a scenario where a customer created the following variants:
Note
To retrieve flag variants, you must use the latest version of Amazon AppConfig Agent in your compute environment. For more information, see the following topics that describe how to update, install, or add the agent for each of the following compute environments:
-
For Lambda compute environments: Adding the Amazon AppConfig Agent Lambda extension
-
For Amazon EC2 compute environments: Step 2: (Required) Installing and starting Amazon AppConfig Agent on Amazon EC2 instances
-
For Amazon ECS compute environments: Starting the Amazon AppConfig agent for Amazon ECS integration
-
For Amazon EKS compute environments: Starting the Amazon AppConfig agent for Amazon EKS integration
To retrieve flag data using the caller context of jane_doe@example.org (who has not opted into the beta program):
curl http://localhost:2772/applications/UIRefresh/environments/Production/configurations/Features \ -H "Context: email=jane_doe@example.org" \ -H "Context: opted_in_to_beta=false" { "ui_refresh": {"_variant":"QA","dark_mode_support":true,"enabled":true} }
To retrieve flag data using the caller context of jane_doe@example.org (who has opted into the beta program):
curl http://localhost:2772/applications/UIRefresh/environments/Production/configurations/Features \ -H "Context: email=jane_doe@example.org" \ -H "Context: opted_in_to_beta=true" { "ui_refresh": {"_variant":"QA","dark_mode_support":true,"enabled":true} }
To retrieve flag data using the caller context of jane_doe@qa-testers.example.org (who is a quality assurance tester at Example Organization):
curl http://localhost:2772/applications/UIRefresh/environments/Production/configurations/Features \ -H "Context: email=jane_doe@qa-testers.example.org" { "ui_refresh": {"_variant":"QA","dark_mode_support":true,"enabled":true} }
To retrieve flag data without caller context (which returns the Default variant)
curl http://localhost:2772/applications/UIRefresh/environments/Production/configurations/Features { "ui_refresh": {"_variant":"Default Variant","enabled":false} }
To retrieve flag data for a traffic splitting scenario to determine if 1 out of 10 random callers receive the 'sample population' variant
for i in {0..9} do ; \ curl http://localhost:2772/applications/UIRefresh/environments/Production/configurations/Features \ -H "Context: email=$i@example.org" { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Sample Population","dark_mode_support":false,"enabled":true} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} } { "ui_refresh": {"_variant":"Default Variant","enabled":false} }