

# Examples with curl for the AWS AppConfig extension in AWS Systems Manager Cloud Extensions

Use curl to call the AWS AppConfig extension, read configurations, evaluate feature flags, and see error responses. This walkthrough reads the configurations of an AWS AppConfig application named `test-demo-app`, with an environment named `demo`, through the extension. Run the steps in one terminal while the runtime serves the extension. The examples use `jq` and `base64`. The examples send no credentials. These examples work only when the authentication of the profile is `none`. To sign requests, see [Authentication](cloud-extensions-security.md#cloud-extensions-security-authentication).

The application has three hosted configuration profiles, each deployed to `demo`:
+ `service-settings` - A freeform profile with the content type `application/json`: `{"greeting":"hello from v1","maxItems":10,"features":["search"]}`.
+ `checkout-flags` - A feature flag profile with three flags:
  + `quick-pay` has the variant `ukPremium` for the rule `(and (eq $country "UK") (in $tier ["gold","platinum"]))` and the variant `ukBasic` for the rule `(eq $country "UK")`. The default variant is `off`, which is disabled. The variants have the attributes `currency`, `maxAmount`, `express`, `methods`, and `tiers`.
  + `new-checkout` has the variant `beta` for the rule `(split pct::50 by::$userId)`. The default variant is `control`, which is disabled.
  + `dark-mode` has no variants. The flag is enabled and has the attribute `contrast`.
+ `simple-flags` - A feature flag profile without variants. Its flag `banner` is enabled, with the attributes `message`, `priority`, and `regions`.

**Step 1. Get a configuration (GetConfiguration)**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"service-settings"}'
```

```json
{"content":"eyJncmVldGluZyI6ImhlbGxvIGZyb20gdjEiLCJtYXhJdGVtcyI6MTAsImZlYXR1cmVzIjpbInNlYXJjaCJdfQo=","contentType":"application/json","revision":"0sU6FR2TSJI","versionLabel":"baseline"}
```

**Step 2. Decode the content**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"service-settings"}' | jq -r .content | base64 --decode
```

```json
{"greeting":"hello from v1","maxItems":10,"features":["search"]}
```

Run the command again. The `revision` is the same, and the extension answers from its cache without calling AWS AppConfig.

**Step 3. Get a flag without context (GetFlag)**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"quick-pay"}'
```

```json
{"enabled":false,"variant":"off"}
```

Without a context, no rule matches, and the extension returns the default variant.

**Step 4. Get a flag with context**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"quick-pay","context":{"country":"UK","tier":"gold"}}'
```

```json
{"enabled":true,"variant":"ukPremium","attributes":{"currency":{"string":"GBP"},"express":{"boolean":true},"maxAmount":{"number":500},"methods":{"stringList":["card","wallet"]},"tiers":{"numberList":[1,2.5]}}}
```

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"quick-pay","context":{"country":"UK","tier":"silver"}}'
```

```json
{"enabled":true,"variant":"ukBasic","attributes":{"currency":{"string":"GBP"},"express":{"boolean":false},"maxAmount":{"number":100},"methods":{"stringList":["card"]},"tiers":{"numberList":[1]}}}
```

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"quick-pay","context":{"country":"FR","tier":"gold"}}'
```

```json
{"enabled":false,"variant":"off"}
```

The extension checks the variants in order, and returns the first variant whose rule matches. `gold` in the UK matches `ukPremium`. `silver` in the UK matches only `ukBasic`. France matches neither rule.

**Step 5. Get a flag with a percentage split**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"new-checkout","context":{"userId":"user-1"}}'
```

```json
{"enabled":true,"variant":"beta","attributes":{"theme":{"string":"v2"}}}
```

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"new-checkout","context":{"userId":"user-2"}}'
```

```json
{"enabled":false,"variant":"control"}
```

The split is deterministic: the same `userId` always gets the same variant, regardless of the instance of the extension that processes the request.

**Step 6. Get a flag without variants**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"dark-mode"}'
```

```json
{"enabled":true,"attributes":{"contrast":{"number":1.5}}}
```

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"simple-flags","flag":"banner"}'
```

```json
{"enabled":true,"attributes":{"message":{"string":"Welcome to the demo"},"priority":{"number":3},"regions":{"stringList":["us-west-2","eu-west-1"]}}}
```

A flag without variants has no `variant` member.

**Step 7. Get a feature flag profile as a whole (GetConfiguration)**

```bash
curl -sS -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags"}' | jq -r .content | base64 --decode | jq .
```

```json
{
  "dark-mode": {
    "contrast": 1.5,
    "enabled": true
  },
  "new-checkout": {
    "_variant": "control",
    "enabled": false
  },
  "quick-pay": {
    "_variant": "off",
    "enabled": false
  }
}
```

`GetConfiguration` evaluates every flag without a context. To evaluate a flag for a context, use `GetFlag`.

**Step 8. Cause error cases**

The following commands need no setup. Each command uses `-i` to show the status and the `X-Amzn-Errortype` header.

A configuration profile that doesn't exist:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"no-such-profile"}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"semanticError":{"problem":"RESOURCE_NOT_FOUND","item":"ConfigurationProfile"}}],"message":"ConfigurationProfile not found","reason":"FIELD_VALIDATION_FAILED"}
```

A flag that doesn't exist:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"no-such-flag"}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"semanticError":{"problem":"FLAG_NOT_FOUND","item":"flag","value":"no-such-flag"}}],"message":"flag 'no-such-flag' not found in configuration 'checkout-flags'","reason":"FIELD_VALIDATION_FAILED"}
```

A flag from a freeform profile:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"service-settings","flag":"greeting"}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"semanticError":{"problem":"FLAG_UNREADABLE","item":"flag","value":"greeting"}}],"message":"unable to read flag 'greeting' from configuration 'service-settings'; use a configuration type that supports flags (e.g. AWS.AppConfig.FeatureFlags)","reason":"FIELD_VALIDATION_FAILED"}
```

A missing parameter:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo"}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"fieldConstraint":{"constraint":{"required":true},"field":"configuration"}}],"message":"1 validation error: configuration is required","reason":"FIELD_VALIDATION_FAILED"}
```

A flag key that isn't valid:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"Quick Pay"}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"fieldConstraint":{"constraint":{"pattern":{"pattern":"^[a-z][a-zA-Z\\d_-]{0,63}$"}},"field":"flag","value":"Quick Pay"}}],"message":"1 validation error: flag must match ^[a-z][a-zA-Z\\d_-]{0,63}$","reason":"FIELD_VALIDATION_FAILED"}
```

A context value that isn't a string:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.GetFlag' -H 'Content-Type: application/x-amz-json-1.1' -d '{"application":"test-demo-app","environment":"demo","configuration":"checkout-flags","flag":"quick-pay","context":{"tier":3}}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","errors":[{"fieldConstraint":{"constraint":{"type":{"expected":"string"}},"field":"context[tier]","value":"3"}}],"message":"1 validation error: context[tier] must be of type string","reason":"FIELD_VALIDATION_FAILED"}
```

An operation that the extension doesn't have:

```bash
curl -sS -i -X POST http://localhost:5333/appconfig/ -H 'X-Amz-Target: AppConfig.DeleteConfiguration' -H 'Content-Type: application/x-amz-json-1.1' -d '{}'
```

```
HTTP/1.1 400 Bad Request
X-Amzn-Errortype: ValidationException
{"__type":"ValidationException","message":"No operation matches the request","reason":"UNKNOWN_OPERATION"}
```

These examples don't show `AccessDeniedException` and `ThrottlingException`, because they need a restricted role or a throttled account.