Managing Application Configuration and Feature Flags with AWS AppConfig
Changing application configuration, such as timeouts, limits, allow lists or feature flags, can cause outages as easily as changing code. AWS AppConfig, a capability of Systems Manager, deploys configuration changes gradually with validation and automatic rollback. This lesson explains AppConfig's resources, configuration sources and validators, deployment strategies, alarm-based rollback, feature flags and how applications retrieve configuration efficiently.
Learning outcomes
After completing this lesson, you will be able to:
- Describe AppConfig applications, environments, configuration profiles and configuration sources.
- Explain how JSON Schema and Lambda validators prevent invalid configuration from being deployed.
- Explain AppConfig deployment strategies, bake time and alarm-based rollback.
- Describe feature flags and how applications retrieve configuration through the AppConfig Agent and API sessions.
Why Configuration Needs Safe Deployment
Many outages are caused not by code but by configuration: a malformed JSON file, a limit set too low or a flag enabled for everyone at once. Keeping configuration in environment variables or files requires a redeployment to change it, and changing it directly in a parameter store applies the change to every consumer instantly with no validation. AWS AppConfig treats configuration changes like code deployments: validated, rolled out gradually, monitored and reversible.
AppConfig Resources
AppConfig uses a small set of resources.
- Application
- A logical grouping, such as the orders service.
- Environment
- A deployment target within the application, such as Beta or Production, with optional CloudWatch alarms that trigger rollback.
- Configuration profile
- Identifies a configuration and where it is stored, with optional validators. Profiles are either feature flag profiles or freeform profiles for arbitrary JSON, YAML or text.
- Configuration source
- Where the content lives: the AppConfig hosted configuration store, Amazon S3, Systems Manager Parameter Store, Systems Manager documents, AWS Secrets Manager or AWS CodePipeline.
- Deployment strategy
- How fast the new configuration reaches the application's targets and how long AppConfig monitors afterwards.
- Deployment
- Rolling out a configuration version to an environment with a strategy.
The hosted configuration store is the simplest source and keeps versions automatically. Using S3 or Parameter Store suits configurations that are already stored there or that are produced by other tools; Secrets Manager suits configurations containing secrets.
AppConfig building blocks
Validators
A configuration profile can have validators that run before every deployment. A JSON Schema validator checks the structure and types of the configuration, for example that maxConnections is an integer between 1 and 500. A Lambda validator runs a function that can perform any check, such as confirming that referenced resources exist or that values are consistent with each other. If validation fails, the deployment does not start, so a syntax error never reaches the application.
Deployment Strategies and Rollback
A deployment strategy has a deployment duration, a growth type and growth factor, and a final bake time. With linear growth and a factor of 20%, the configuration becomes available to an additional 20% of targets at each interval; with exponential growth, the share doubles from the initial factor. After the configuration reaches 100%, AppConfig keeps monitoring for the bake time before marking the deployment complete. AWS provides predefined strategies such as AppConfig.AllAtOnce, AppConfig.Linear50PercentEvery30Seconds, AppConfig.Linear20PercentEvery6Minutes and AppConfig.Canary10Percent20Minutes.
If any CloudWatch alarm associated with the environment enters the ALARM state during the deployment or bake time, AppConfig rolls back automatically to the previous configuration version. AppConfig needs a role that allows it to read the alarms. A deployment can also be stopped manually. Because rollback is driven by the same alarms that monitor the application, a configuration change that increases errors is reversed without anyone redeploying.
aws appconfig start-deployment --application-id a1b2c3 --environment-id prod01 \
--configuration-profile-id flags01 --configuration-version 7 \
--deployment-strategy-id AppConfig.Canary10Percent20Minutes \
--description "Enable new pricing engine for 10 percent first"Feature Flags
Feature flag configuration profiles store flags in a structured format managed in the console or API. Each flag has an enabled state and optional attributes with constraints, such as a percentage or a list of customer tiers. Multi-variant flags return different values to different users based on rules evaluated against context the application supplies, such as user ID or Region, which supports gradual rollouts to user segments and A/B experiments. Flags can be marked short-term, so that they can be identified and removed after release. As explained in the Deployment Strategies module, flags let teams deploy code dark and release features independently of deployments.
Retrieving Configuration in Applications
Applications retrieve configuration through the AppConfig Data API: StartConfigurationSession returns a token, and GetLatestConfiguration returns the configuration and a new token, returning content only when it has changed. Polling efficiently and caching correctly is easy to get wrong, so AWS provides the AppConfig Agent, which handles sessions, polling, caching and evaluation of multi-variant flags and serves configuration to the application on a local HTTP endpoint (port 2772). The agent is available as an AWS Lambda extension, as a sidecar container for Amazon ECS and Amazon EKS, and as a package for EC2 and on-premises servers. Because the agent serves a cached copy, applications keep working even if AppConfig is briefly unreachable.
AppConfig extensions add actions at deployment events, such as sending a notification to SNS or EventBridge when a deployment starts, completes or rolls back, or backing up configuration to S3.
A Safe Throttle Change
An API's rate limit per customer is stored in a Parameter Store parameter that the application reads at start-up. A recent change set the limit to 5 instead of 500, every instance had to be restarted to pick it up, and when they restarted, legitimate traffic was throttled for an hour.
-
Profile
Create a freeform configuration profile for the limits, sourced from the hosted store, with a JSON Schema validator requiring each limit to be between 50 and 5,000.
-
Environment alarms
Associate the Production environment with the API's 429-rate and 5xx alarms.
-
Strategy
Deploy changes with AppConfig.Canary10Percent20Minutes so that a bad value affects 10% of targets and is rolled back by the alarms.
-
Retrieval
Run the AppConfig Agent as a sidecar so the application reads limits from localhost without restarts.
A configuration deployment with AppConfig completes, and 10 minutes later errors rise. The environment has an error alarm and the strategy has a 5-minute final bake time. Will AppConfig roll back?
Show answer
No. AppConfig monitors alarms only during the deployment and the final bake time. The bake time should be long enough to cover the period in which problems are likely to appear.
Exam Tips
Remember for the exam
- AppConfig deploys configuration with validators (JSON Schema or Lambda), gradual deployment strategies, a final bake time and automatic rollback on CloudWatch alarms.
- Configuration sources include the hosted store, S3, Parameter Store, SSM documents, Secrets Manager and CodePipeline.
- Feature flag profiles, including multi-variant flags, separate feature release from code deployment.
- Use the AppConfig Agent (Lambda extension, ECS/EKS sidecar, EC2 package) to cache configuration and avoid restarts.