Changing Application Behaviour at Runtime with AWS AppConfig Feature Flags
This lesson explains how AWS AppConfig, originally a capability of AWS Systems Manager, lets you change an application's behaviour at runtime, safely and without redeploying code.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how applications, environments, configuration profiles and deployment strategies are related.
- Explain how feature flags and their attributes control behaviour without a deployment.
- Explain how deployment strategies and CloudWatch alarms make configuration changes safe.
- Distinguish AppConfig from Lambda environment variables.
Building blocks
AppConfig organises configuration data in a hierarchy. An application represents the software whose behaviour is being configured, such as the orders service. Each application has environments, such as dev, test and prod, which are the targets that configuration is deployed to. An environment can be associated with CloudWatch alarms that AppConfig watches during every deployment to it.
A configuration profile describes one set of configuration data and where it is stored. A freeform profile holds any JSON, YAML or text, stored in AppConfig itself or in sources such as S3, Parameter Store or Secrets Manager. A feature flag profile holds flags and their attributes in a format designed for turning features on and off. Every new version of a profile can be checked by validators before it is deployed: a JSON Schema validator checks the structure, and a Lambda validator can apply any rule, such as rejecting a discount above 50%. A configuration that fails validation is never deployed. The following table summarises the concepts.
| Concept | Meaning |
|---|---|
| Application | The app whose configuration you manage |
| Environment | A deployment target such as dev, test or prod |
| Configuration profile | Free-form configuration (stored in AppConfig, S3, Parameter Store and more) or feature flags |
| Validator | A JSON Schema or Lambda function that checks each new version before deployment |
The following diagram shows how the building blocks fit together.

AppConfig building blocks
Feature flags
AWS AppConfig feature flags control the behaviour of an application without a new deployment. The following list describes the types of flag.
- A simple flag turns a feature on or off.
- Flags can carry attributes, such as a percentage or a list of allowed users.
- Multi-variant flags return different values to different users.
Safe deployments
A deployment strategy controls how quickly new configuration reaches clients, for example linearly over ten minutes followed by a bake time. AppConfig rolls back automatically if an associated CloudWatch alarm fires.
Reading configuration
Applications fetch configuration through the AppConfig Data API or the AppConfig Lambda extension, which polls in the background and caches it locally.
import json, urllib.request
URL = "http://localhost:2772/applications/orders/environments/prod/configurations/feature-flags"
def handler(event, context):
flags = json.load(urllib.request.urlopen(URL))
if flags["new-checkout"]["enabled"]:
return new_checkout(event)
return old_checkout(event)AppConfig vs environment variables
Lambda environment variables and AppConfig can both supply configuration, but they behave very differently when a value changes.
An environment variable is part of the function's configuration. Changing it updates the function, and with versions and aliases it requires publishing a new version, so a configuration change goes through the same process as a code release. The new value applies to every invocation at once, and there is no check that the value is valid. Undoing a mistake means another update.
With AppConfig, the function reads its configuration at run time, usually through the AppConfig Lambda extension, so changing a value requires no change to the function. Each change is validated before deployment and rolled out by a deployment strategy, for example to 20% of clients every few minutes, while AppConfig watches the environment's alarms. If an alarm fires, AppConfig rolls the configuration back automatically. Environment variables suit values that rarely change, such as a table name; AppConfig suits settings and feature flags that change often or carry risk. The following table summarises the differences.
AppConfig or environment variable?
Turning off a broken feature in seconds
A new recommendation feature, released behind an AppConfig feature flag, starts causing errors for some users. Because the flag is deployed with a linear strategy over 20 minutes and a CloudWatch alarm is attached to the environment:
| Time | Event |
|---|---|
| 09:00 | Flag deployment starts: 10%, then 20% of hosts receive recommendations: true |
| 09:06 | Error alarm enters ALARM |
| 09:06 | AppConfig rolls the configuration back automatically |
| 09:07 | The application's next poll of the AppConfig agent returns false; errors stop |
No code was redeployed, and most users never saw the problem. With an environment variable instead, the same change would have needed a deployment both to enable and to disable it.
How does AppConfig limit the impact of a bad configuration change?
Show answer
It rolls the change out gradually according to a deployment strategy and watches CloudWatch alarms; if an alarm fires during the deployment, AppConfig rolls the change back. Validators can also reject invalid configuration before it is deployed.
Exam Tips
Remember for the exam
- To turn features on or off without redeploying, use AppConfig feature flags.
- To validate configuration and roll it out gradually with automatic rollback, use an AppConfig deployment strategy with an alarm.
- To read AppConfig data efficiently in Lambda, use the AppConfig Lambda extension.
- To show a feature to only some users, use multi-variant feature flags.