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.
The application has three hosted configuration profiles, each deployed to demo:
-
service-settings- A freeform profile with the content typeapplication/json:{"greeting":"hello from v1","maxItems":10,"features":["search"]}. -
checkout-flags- A feature flag profile with three flags:-
quick-payhas the variantukPremiumfor the rule(and (eq $country "UK") (in $tier ["gold","platinum"]))and the variantukBasicfor the rule(eq $country "UK"). The default variant isoff, which is disabled. The variants have the attributescurrency,maxAmount,express,methods, andtiers. -
new-checkouthas the variantbetafor the rule(split pct::50 by::$userId). The default variant iscontrol, which is disabled. -
dark-modehas no variants. The flag is enabled and has the attributecontrast.
-
-
simple-flags- A feature flag profile without variants. Its flagbanneris enabled, with the attributesmessage,priority, andregions.
Step 1. Get a configuration (GetConfiguration)
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"}'
{"content":"eyJncmVldGluZyI6ImhlbGxvIGZyb20gdjEiLCJtYXhJdGVtcyI6MTAsImZlYXR1cmVzIjpbInNlYXJjaCJdfQo=","contentType":"application/json","revision":"0sU6FR2TSJI","versionLabel":"baseline"}
Step 2. Decode the content
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
{"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)
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"}'
{"enabled":false,"variant":"off"}
Without a context, no rule matches, and the extension returns the default variant.
Step 4. Get a flag with context
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"}}'
{"enabled":true,"variant":"ukPremium","attributes":{"currency":{"string":"GBP"},"express":{"boolean":true},"maxAmount":{"number":500},"methods":{"stringList":["card","wallet"]},"tiers":{"numberList":[1,2.5]}}}
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"}}'
{"enabled":true,"variant":"ukBasic","attributes":{"currency":{"string":"GBP"},"express":{"boolean":false},"maxAmount":{"number":100},"methods":{"stringList":["card"]},"tiers":{"numberList":[1]}}}
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"}}'
{"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
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"}}'
{"enabled":true,"variant":"beta","attributes":{"theme":{"string":"v2"}}}
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"}}'
{"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
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"}'
{"enabled":true,"attributes":{"contrast":{"number":1.5}}}
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"}'
{"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)
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 .
{ "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:
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:
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:
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:
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:
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:
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:
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.