
Feature Flags and Config Deployment with AWS AppConfig
Deploy feature flags with AWS AppConfig: model config, roll out gradually with a canary strategy, and roll back automatically.
Imagine a product manager asks you to turn off the new checkout flow because it's causing errors in production. The change is a single boolean, but that boolean is baked into your application code, so flipping it means a commit, a build, a pipeline run, and a deploy. That's fifteen minutes if everything goes right, and the whole time the broken flow is live. The fix was trivial; the delivery mechanism was the problem.
Configuration shouldn't ride the same rails as code. AWS AppConfig helps you safely change application behavior in production without redeploying code, using feature flags and dynamic free-form configurations to control how your app runs in real time.
This post builds that out hands-on. We'll model an application's config, deploy feature flags with a canary-style rollout, read them back the way an application would, and set up the bake time and rollback that make it safe.
The Config Change That Needs a Redeploy
Hardcoding configuration (flags, timeouts, limits, allow-lists) couples trivial changes to your entire release process:
- Blast radius: a one-line flag change goes through the same build-and-deploy as a thousand-line feature, inheriting all of its risk and latency.
- Slow response: when something breaks, you can't just flip a switch; you wait for a pipeline.
AppConfig breaks that coupling by storing configuration outside your code and deploying it on its own schedule. To use it, you first describe your config in AppConfig's model.
The AppConfig Model
AppConfig organizes configuration into a small hierarchy. Each piece has one responsibility:
- Application: a logical container for one app's configuration (e.g.,
checkout-service).
- Environment: a deployment target within the application, like
devorprod. Deployments and monitoring are scoped per environment.
- Configuration profile: a source of config data. There are two types: feature flags (structured on/off toggles) and freeform (any JSON/YAML/text, for things like tuning parameters).
- Configuration version: an immutable snapshot of the profile's data. You deploy a specific version to an environment.
Create the Application and Environments
Start by creating the application and two environments. Capture the IDs, because every later call references them:
# The application: a container for this service's configurationAPP_ID=$(aws appconfig create-application \ --name checkout-service \ --query 'Id' --output text)
# Two deployment targets; deployments and monitoring are per-environmentDEV_ENV_ID=$(aws appconfig create-environment \ --application-id "$APP_ID" --name dev \ --query 'Id' --output text)
PROD_ENV_ID=$(aws appconfig create-environment \ --application-id "$APP_ID" --name prod \ --query 'Id' --output text)
echo "App: $APP_ID Dev: $DEV_ENV_ID Prod: $PROD_ENV_ID"Create a Feature-Flag Profile and Version
Now a feature-flag profile. The
--type tells AppConfig to validate the data against its feature-flag schema, and --location-uri hosted means AppConfig stores the data itself (rather than pointing at S3 or Parameter Store):# Feature-flag profile, hosted directly in AppConfigPROFILE_ID=$(aws appconfig create-configuration-profile \ --application-id "$APP_ID" \ --name feature-flags \ --location-uri "hosted" \ --type "AWS.AppConfig.FeatureFlags" \ --query 'Id' --output text)Define two flags.
dark_mode is on and new_checkout is off, which is the state we'll change later to simulate a controlled release. The flags block declares the flags; the values block sets their current state:cat > feature-flags.json << 'EOF'{ "version": "1", "flags": { "dark_mode": { "name": "Dark Mode" }, "new_checkout": { "name": "New Checkout Flow" } }, "values": { "dark_mode": { "enabled": true }, "new_checkout": { "enabled": false } }}EOF
# Each version is an immutable snapshot; capture the version number to deploy.# The CLI requires a positional outfile where it saves the stored config body,# so send that to a scratch file and keep only the version number via --query.VERSION_1=$(aws appconfig create-hosted-configuration-version \ --application-id "$APP_ID" \ --configuration-profile-id "$PROFILE_ID" \ --content fileb://feature-flags.json \ --content-type "application/json" \ /tmp/appconfig-version-body.json \ --query 'VersionNumber' --output text)The config now exists but isn't live anywhere. Making it live is a deployment, and that's where the safety comes in.
Deploying Config Like a Canary
A deployment strategy defines how a configuration rolls out: the overall duration, a percentage of targets to receive it during each interval, the algorithm for how that percentage grows, and a bake time. This is the same canary thinking you'd apply to code, now applied to config.
Create a linear strategy that rolls out over 10 minutes, 20% at a time:
# Linear: +20% of targets every (duration / growth steps)STRATEGY_ID=$(aws appconfig create-deployment-strategy \ --name "Linear20Over10Min" \ --deployment-duration-in-minutes 10 \ --growth-factor 20 \ --growth-type LINEAR \ --final-bake-time-in-minutes 5 \ --replicate-to NONE \ --query 'Id' --output text)With a growth factor of 20, a linear deployment initially makes the configuration available to 20% of targets, then steps to 40% after a fifth of the duration passes, continuing until 100%. The
--final-bake-time-in-minutes 5 is the monitoring window after reaching 100%, and we'll come back to why it matters.Now deploy. Dev gets the change instantly using the AWS-provided
AppConfig.AllAtOnce strategy; prod gets our gradual rollout:# Dev: deploy immediately for fast feedback at low stakesaws appconfig start-deployment \ --application-id "$APP_ID" \ --environment-id "$DEV_ENV_ID" \ --deployment-strategy-id "AppConfig.AllAtOnce" \ --configuration-profile-id "$PROFILE_ID" \ --configuration-version "$VERSION_1"
# Prod: deploy gradually over 10 minutesaws appconfig start-deployment \ --application-id "$APP_ID" \ --environment-id "$PROD_ENV_ID" \ --deployment-strategy-id "$STRATEGY_ID" \ --configuration-profile-id "$PROFILE_ID" \ --configuration-version "$VERSION_1"Check the prod deployment's progress. Note that
list-deployments returns a point-in-time snapshot, so a single call shows only the current percentage. Right after you start the deploy, that's 20.0 , the first linear step (a linear deployment makes the config available to the growth-factor percentage immediately, not 0%):aws appconfig list-deployments \ --application-id "$APP_ID" \ --environment-id "$PROD_ENV_ID" \ --query 'Items[0].{State:State,Percent:PercentageComplete}'With a 20% linear growth factor over 10 minutes, the rollout steps up by 20 points every 2 minutes (
duration / (100 / growth_factor) ), reaches 100%, then holds for the 5-minute final bake. To watch those transitions instead of polling by hand, loop the call in your shell. Each line is timestamped so you can see the percentage climb and the state move from DEPLOYING to BAKING to COMPLETE :# Poll every 15s and print a timestamped state line; Ctrl-C once it reads COMPLETEwhile true; do printf '%s ' "$(date +%T)" aws appconfig list-deployments \ --application-id "$APP_ID" \ --environment-id "$PROD_ENV_ID" \ --query 'Items[0].{State:State,Percent:PercentageComplete}' \ --output text sleep 15doneThe config is rolling out. Now let's see how an application actually consumes it.
How the Application Reads It
An application retrieves config by first establishing a session with
StartConfigurationSession , then making periodic calls to GetLatestConfiguration to check for and retrieve the latest data. Those periodic calls are the heart of it: config changes while the app is running (you flip new_checkout off mid-deploy), so the app polls on an interval and applies whatever comes back. The session call happens once to open the stream; the fetch call repeats for the life of the app:
Start a session against the dev environment. It returns the token for your first fetch:
# Open a session; returns the token for the FIRST GetLatestConfiguration callTOKEN=$(aws appconfigdata start-configuration-session \ --application-identifier "$APP_ID" \ --environment-identifier "$DEV_ENV_ID" \ --configuration-profile-identifier "$PROFILE_ID" \ --query 'InitialConfigurationToken' --output text)Now fetch the current configuration with that token. This is the call the app repeats on each poll:
# Fetch the current configuration data.aws appconfigdata get-latest-configuration \ --configuration-token "$TOKEN" \ --output text \ /tmp/appconfig-latest.json
python3 -m json.tool /tmp/appconfig-latest.jsonFor the dev environment, which received the all-at-once deploy of version 1, this prints the resolved flag values:
{ "dark_mode": { "enabled": true }, "new_checkout": { "enabled": false }}Running those two commands by hand gives you one fetch. An application wraps the fetch in the poll loop from the diagram, and two values from each response drive it. Each call to
GetLatestConfiguration returns a fresh NextPollConfigurationToken , and the next call uses it, which chains one poll to the next.Each token stays valid for up to 24 hours to support long polling, and AWS's guidance is to use a token once and then advance to the new one so you keep moving forward through updates. The response also carries a
NextPollIntervalInSeconds that tells your client how long to wait before the next poll. In pseudocode:token = StartConfigurationSession(...).InitialConfigurationTokenloop: response = GetLatestConfiguration(token) if response.Configuration is non-empty: # empty means no change since last poll applyConfig(response.Configuration) token = response.NextPollConfigurationToken # always advance; don't reuse the old token sleep(response.NextPollIntervalInSeconds)In production you rarely write that loop yourself. The AWS AppConfig Agent is the recommended method for retrieving flags and configuration, and it's supported across EC2, ECS, EKS, and Lambda. It runs as a sidecar or Lambda extension, handles the session, polling, and caching, and exposes config to your app over a local HTTP call. Either way, retrieval is a read against a cache, not a code deploy.
Retrieval is the easy half. The reason to trust config in production is what happens when a deployment goes wrong.
Safe Rollouts: Bake Time, Rollback, and Validators
Decoupling config from code only helps if a bad config can't take you down. AppConfig provides three guards:
- Final bake time with automatic rollback. The final bake time is how long AppConfig monitors CloudWatch alarms after the config reaches 100% of targets; if an alarm triggers during that window, AppConfig rolls back the deployment. To arm it, associate a CloudWatch alarm with the environment via an environment monitor, so a spike in your error-rate alarm reverts the config automatically.
- Validators catch bad data before it ships. A configuration profile can carry validators that run when you create a version: a JSON Schema validator checks structure, and a Lambda validator runs arbitrary logic. A version that fails validation can't be deployed, so a malformed flag file never reaches an environment.
- Gradual strategy limits exposure. The linear (or exponential) rollout means a problem surfaces at 20% of targets, during bake time, before it reaches everyone, which is the same reason canary deployments beat big-bang ones.
Together these make a config change behave like a well-governed code deploy: validated before release, rolled out gradually, watched by alarms, and reverted automatically if the alarms fire. Safety travels with the config, not with the code pipeline.
Wrapping Up
AppConfig moves configuration out of your codebase and gives it a release process of its own. The model is small (application, environment, configuration profile, version), and the safety comes from treating a config change like a deployment: a strategy that rolls out gradually, a bake time that watches CloudWatch alarms, validators that reject bad data, and automatic rollback when something trips. Flipping that checkout flag off becomes a deployment that takes seconds and protects itself, not a 15-minute pipeline run.
Cleaning Up
Tear down the lab when you're done. AppConfig deletes bottom-up: remove the hosted configuration version, then the profile and environments, then the deployment strategy, and finally the application. The profile and both environments were read via
GetLatestConfiguration during the lab, so AppConfig's deletion-protection guard treats them as in use. Pass --deletion-protection-check BYPASS on those three deletes to proceed:# 1. Hosted configuration version (must go before its profile)aws appconfig delete-hosted-configuration-version \ --application-id "$APP_ID" \ --configuration-profile-id "$PROFILE_ID" \ --version-number "$VERSION_1"
# 2. Configuration profile (BYPASS: it was read during the lab)aws appconfig delete-configuration-profile \ --application-id "$APP_ID" \ --configuration-profile-id "$PROFILE_ID" \ --deletion-protection-check BYPASS
# 3. Both environments (BYPASS skips the deletion-protection check)aws appconfig delete-environment \ --application-id "$APP_ID" \ --environment-id "$DEV_ENV_ID" \ --deletion-protection-check BYPASS
aws appconfig delete-environment \ --application-id "$APP_ID" \ --environment-id "$PROD_ENV_ID" \ --deletion-protection-check BYPASS
# 4. Deployment strategy (customer-owned; the AWS-managed ones can't be deleted)aws appconfig delete-deployment-strategy \ --deployment-strategy-id "$STRATEGY_ID"
# 5. Application, now that it has no childrenaws appconfig delete-application \ --application-id "$APP_ID"The next step is to make it production-grade. Add a JSON Schema validator to the profile so malformed flags can't deploy, attach a CloudWatch alarm monitor to the prod environment so a bad rollout reverts itself, and retrieve config through the AWS AppConfig Agent instead of hand-writing the polling loop. At that point, changing production behavior is a switch you can flip with confidence.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article