

# How the AWS AppConfig extension in AWS Systems Manager Cloud Extensions works

The AWS AppConfig extension caches each configuration in memory and refreshes the configuration in the background.

1. **First request** – When your application asks for a configuration that the cache doesn't hold, the extension starts a configuration session with AWS AppConfig. The extension retrieves the configuration and stores it in memory. The request waits for that retrieval.

1. **Cached requests** – The extension serves later requests from the cache.

1. **Background polls** – Every **Poll interval** seconds, the extension asks AWS AppConfig for the latest configuration. If you deployed a new version, the extension stores it, and the next request gets it.

1. **Eviction** – If AWS AppConfig stops serving a deployment, for example because you deleted the configuration, the extension removes the configuration from the cache.

**Topics**
+ [Feature flag evaluation](#cloud-extensions-ext-appconfig-how-it-works-feature-flag-evaluation)
+ [How the extension reacts to errors](#cloud-extensions-ext-appconfig-how-it-works-how-the-extension-reacts-to-errors)

## Feature flag evaluation
<a name="cloud-extensions-ext-appconfig-how-it-works-feature-flag-evaluation"></a>

For a multi-variant feature flag, AWS AppConfig sends the extension the flags with their variants and rules. The extension evaluates the rules for each `GetFlag` request, against the `context` of that request:
+ The extension checks the variants in order and returns the first variant whose rule matches. If no rule matches, it returns the default variant.
+ For a profile without variants, `GetFlag` returns the flag as deployed, and the context has no effect.
+ Each attribute keeps the type that it has in the flag data: string, number, boolean, string list, or number list.

## How the extension reacts to errors
<a name="cloud-extensions-ext-appconfig-how-it-works-how-the-extension-reacts-to-errors"></a>

These rules apply when the extension calls AWS AppConfig: on a request for a configuration that isn't cached, and in each background poll.

When the cache holds the configuration, every failed poll has the same result. The extension keeps serving the cached configuration, and it tries again after the longer retry interval. When the cache holds nothing, the request returns the error, and the extension keeps trying in the background:


| Result from AWS AppConfig | Error returned | Next try when the cache holds nothing | 
| --- | --- | --- | 
| The application, environment, profile, or deployment doesn't exist | `ValidationException`, `RESOURCE_NOT_FOUND` | After the longer retry interval | 
| Access denied | `AccessDeniedException` | After the longer retry interval | 
| Credentials rejected or expired | `AccessDeniedException` | After 10 seconds | 
| Throttling | `ThrottlingException` | After 10 seconds | 
| The extension can't reach AWS AppConfig, or it has no credentials | `InternalServerException`, with the message `Unable to call AWS AppConfig` | After 1 second | 
| Internal error of AWS AppConfig | `InternalServerException` | After 10 seconds | 

The longer retry interval is 60 seconds, or the **Poll interval** if that's longer.

This behavior has the following results:
+ **Outages don't break your application** – After the extension caches a configuration, your application keeps getting it even if AWS AppConfig becomes unreachable.
+ **A missing configuration keeps retrying** – The extension keeps trying to retrieve a configuration that you asked for, even if it doesn't exist yet. When you create and deploy it, the extension picks it up.
+ **A deployment can end** – If AWS AppConfig stops serving a deployment, the extension removes the deployment from the cache and stops serving it.