The usage of AWS AppConfig Function Flags

AWS not too long ago introduced AWS AppConfig Function Flags. Function flagging is an impressive device that permits engineers to soundly push out new options to consumers, however doing so in a measured and typically sluggish manner. On this weblog publish, you are going to find out about what function flags are, what are the advantages to the use of them, and what are some use-cases for function flags.

The “previous” option to liberate a function is to first construct the code, then take a look at it in QA, and get in a position to deploy to Manufacturing. Engineers want to align the code merge and deployment with the date and time when advertising desires it launched. As soon as this is all in a position to move, on liberate day, you push out your new code to Manufacturing, and hope the whole lot is going easily. So long as timing is going smartly, your consumers can get entry to the function unexpectedly. Engineers feverishly observe efficiency metrics to make certain that the brand new function didn’t introduce instability. That is now and again referred to as “a push-and-pray deployment” because you don’t know the way your code will behave on Manufacturing till everyone already has it.

Fashionable tool practices use function flags when freeing new capability. The usage of this method, engineers separate code from configuration information. One can conceal their function at the back of a configuration toggle (a function flag) and deploy the code to Manufacturing. Alternatively, for the reason that code is hidden at the back of their flag, consumers can’t get entry to the function. The engineer can turn the flag for an overly restricted team of customers (as an example, simply themselves, or simply inner customers) and take a look at out the function on Manufacturing. The engineer can then regularly open get entry to to an increasing number of customers. Assuming no alarms are going off throughout the sluggish liberate of the function, and different metrics are the place you are expecting them, the deployment continues safely till 100% of customers have the brand new function.

There are other use-cases for and sorts of function flags, relying at the want. As famous above, a liberate flag can be utilized to expand a brand new function for your software. Engineers code the function, deploy it whilst the function is hidden at the back of a function flag, and regularly make the function to be had for customers, all whilst tracking your software’s well being. Experimentation flags, used for A/B trying out, are very helpful for accumulating information about permutations of capability. As a substitute of arguing which variation may well be higher, an A/B take a look at gives you actual information to turn out out which experiment is maximum a success. CloudWatch Plainly is an impressive answer for experimentation function flags. Operations flags are used for tuning your software. Engineers may put values just like the selection of simultaneous background duties right into a function flag, so they are able to flip that up and down, relying at the stipulations on manufacturing.

AWS AppConfig Function flags help you expectantly deploy adjustments to manufacturing via including protection guard rails in your function flags. First, AWS AppConfig help you set validators and constraints for every flag. If a flag information is non-boolean (as an example, a bunch), consumers can set an non-compulsory minimal and most worth for that quantity to verify some unintended flag worth does no longer reason an issue and even an outage in manufacturing. Moreover, you’ll be able to liberate your flags temporarily or regularly via environment a Deployment Technique in your flag updates. Flag updates may also be rolled out straight away, or higher but, over the process hours, thus restricting the blast radius of any surprising exchange. In the end, AWS AppConfig will robotically roll again any function flag replace if a CloudWatch alarm is caused.

Now let’s arrange some function flags in AWS AppConfig so you’ll be able to see the way it truly works.

The way to create a function flag

Signal into the AWS Control Console, and pass to AWS AppConfig. Word: within the Python instance under, we’re the use of us-east-1 as our AWS_REGION; you’ll be able to use any AWS Area, however simply you should definitely replace AWS_REGION correctly in your Area. You’ll then be precipitated to outline an Utility for which the function flags might be used. An software is a namespace for organizing function flags or different configuration information. For the sake of the demo under, name your new Utility FlagsDemo.

Once you have given your software a reputation, then you definately will create a Configuration Profile this is of variety Function Flags. Let’s title this one CheckoutFlags. This Configuration Profile may also be regarded as a number of similar flags. You’ll have one flag in every Configuration Profile, or dozens of flags.

Now let’s create a easy Boolean flag. For this case, let’s say you might be an engineer at an organization does ecommerce. You might be making plans on including make stronger for Bitcoin bills at checkout. So, you create a flag in AWS AppConfig referred to as allow-bitcoin-at-checkout, and default it to disabled. You write code that code has conditional common sense in it to keep an eye on get entry to to that function in response to the price of the flag and take a look at it with each the function enabled and disabled. Whilst you push to manufacturing you’ll be able to set the flag to disabled to forestall consumers from having access to the function. As soon as you’re ready, you replace the toggle in AppConfig, flipping the flag to enabled and deploying it to Manufacturing regularly the use of AppConfig’s Deployment Methods over the process an hour. After validating your metrics throughout that hour, 100% of your consumers can now use Bitcoin at checkout.

Subsequent, let’s create a extra complicated flag. On this case, you are going to specify a couple of checkout choices the use of a unmarried flag. Let’s say your staff is launching a brand new function, make stronger for Bitcoin buying. You need to provide a reduction (for a restricted time) in case your customers make a selection Bitcoin at checkout. On this case, you possibly can use flag Attributes, in addition to Characteristic constraints. Inside your allow-bitcoin-at-checkout flag you’ll be able to upload 3 Attributes: default-currencybitcoin-discount-percent, and bitcoin-discount-end-date. Understand that for every Characteristic, we have now additionally added an non-compulsory Constraint. Those constraints, which may also be regex, enums, or quantity levels, are an extra protection guard rails to be sure that your flag information is what is anticipated. They validate the flag information previous to it being deployed.

This extra complicated flag lets you organize 3 configurations in one flag. In fact, those is also damaged out into 3 separate flags as smartly. Relying in your software code, use-case, and workflows, that can make extra sense. Alternatively, retaining those grouped right into a unmarried flag lets you keep arranged and stay your flags tidy.

Another factor about retaining issues tidy. Did you notice the test field classified Quick time period flag within the screenshot? With AWS AppConfig Function flags, you’ll be able to stay your flags arranged via figuring out some flags as non permanent. Quick-term flags are incessantly used to release a brand new function. After the function is introduced, you’ll want to blank up the code and the flags which are now not used. Figuring out a flag as non permanent will assist you to stay observe of flags that you’re going to deprecate one day. If you happen to determine a flag as non permanent, you’ll be able to filter out in this characteristic within the console. You don’t seem to be required to spot any flags as non permanent. This identifier is most effective intended that can assist you filter out on transient flags and blank up unused flags for your software configuration and code.

Within the instance above, the Bitcoin promotion is a restricted time be offering. Thus, it is a non permanent function flag. As soon as the promotion is finished, this flag and naturally its corresponding code, must be wiped clean up. The usage of the AWS AppConfig console, you’ll be able to simply to find which flags are non permanent flags.

Demo of function flags in motion

Let’s put this all in conjunction with a brief demo. First be sure your allow-bitcoin-at-checkout flag is disabled via the use of the slider toggle at the correct. Then click on “Save a brand new model” in the event you haven’t already.

AWS AppConfig Console. Shows a single feature flag that is ready to be deployed.

Now let’s deploy this preliminary model with the flag disabled. Deployments in AppConfig make your configuration adjustments visual to purchasers once they ballot for configuration information the use of the GetLastestConfiguration API. To do that click on Get started deployment. Throughout the deployment display screen it is important to create an Atmosphere to continue. Environments are logical deployment teams, such Beta vs Manufacturing, as a way to isolate the rollout of configuration adjustments to other levels or parts of your software. Let’s name this new atmosphere Beta.

There’s some other protection guard rail this is price highlighting throughout Atmosphere advent. Word how there’s a “Screens” segment that permits you to optionally specify a CloudWatch alarm. AWS AppConfig will robotically roll again any function flag replace if that alarm is caused throughout a deployment. Via configuring computerized rollback in response to CloudWatch alarms, you’ve gotten otherwise to soundly replace flags.

the AWS AppConfig console. Shows how to set up an Environment to which you would deploy configuration.

Click on Create atmosphere and also you must be taken again to the Start deployment display screen the place your new Atmosphere might be pre-selected. Right here, for the sake of the demo, exchange Deployment technique to AppConfig.AllAtOnce (Fast).

AWS AppConfig console. Shows how to deploy configuration using the AllAtOnce deployment strategy.

Click on Get started deployment to continue.

Now let’s check out operating a small software that may display function flags in motion. The python script under will get started a neighborhood webserver and can open up a ridicule checkout web page for your internet browser. To start with the function flag might be became off so the web page will don’t have any connection with bitcoin being a foreign money possibility. We can then permit and re-deploy our allow-bitcoin-at-checkout flag and spot how the web page can reconfigure itself to turn bitcoin as an possibility with out requiring any code adjustments.

The usage of a textual content editor, save the next document in the community as and run it the use of python3. It is important to have the AWS SDK for Python put in which you’ll be able to do via operating pip set up boto3. You’ll additionally want to configure environmental AWS credentials which you’ll be able to do with the AWS CLI by the use of aws configure. The IAM person or position tied to the credentials you configure will want to have permissions for "appconfig:GetLatestConfiguration" and "appconfig:StartConfigurationSession".

from datetime import datetime, timedelta
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
from string import Template
import webbrowser
import boto3

AWS_REGION = "us-east-1"

cached_config_data = {}
cached_config_token = None
cached_token_expiration_time = None

def get_config():
    world cached_config_token
    world cached_config_data
    world cached_token_expiration_time
    appconfigdata = boto3.shopper("appconfigdata", region_name=AWS_REGION)

    # If we wouldn't have a token but, name start_configuration_session to get one
    if no longer cached_config_token or >= cached_token_expiration_time:
        start_session_response = appconfigdata.start_configuration_session(
        cached_config_token = start_session_response["InitialConfigurationToken"]

    get_config_response = appconfigdata.get_latest_configuration(
    # Reaction all the time features a contemporary token to make use of in subsequent name
    cached_config_token = get_config_response["NextPollConfigurationToken"]
    # Token will expire if no longer refreshed inside of 24 hours, so stay observe of
    # the predicted expiration time minus a little of padding
    cached_token_expiration_time = + timedelta(hours=23, mins=59)
    # 'Configuration' within the reaction will most effective be populated the primary time we
    # name GetLatestConfiguration or if the config contents have modified since
    # the remaining time we referred to as. So if it is empty we all know we have already got the most recent
    # config, another way we want to replace our cache.
    content material = get_config_response["Configuration"].learn()
    if content material:
        check out:
            cached_config_data = json.a lot(content material.decode("utf-8"))
            print("won new config information:", cached_config_data)
        with the exception of json.JSONDecodeError as error:
            elevate ValueError(error.msg) from error

    go back cached_config_data

def get_html():
    # For simplicity this code fetches a contemporary config from AppConfig each and every time a web page is served.
    # In a real software generally you possibly can need to ballot AppConfig within the background
    # and cache the effects.
    config = get_config()
    allow_bitcoin_flag = config["allow-bitcoin-at-checkout"]

    if allow_bitcoin_flag["enabled"]:
        dropdown_display_css = "preliminary"
        default_currency = allow_bitcoin_flag["default-currency"]
        bitcoinDiscountPercentage = allow_bitcoin_flag["bitcoin-discount-percentage"]
        bitcoinDiscountEndDate = allow_bitcoin_flag.get("bitcoin-discount-end-date", "")
        default_currency = "USD"
        dropdown_display_css = "none"
        bitcoinDiscountPercentage = 0
        bitcoinDiscountEndDate = ""

    if bitcoinDiscountEndDate:
        discountEndDatetime = datetime.strptime(bitcoinDiscountEndDate, “%m/%d/%Y”)
        if of late() > discountEndDatetime:
            bitcoinDiscountPercentage = 0

    usd_selected = "chosen='chosen'" if default_currency == "USD" else ""
    btc_selected = "chosen='chosen'" if default_currency == "BTC" else ""

    html_template = """
    <meta content material="textual content/html;charset=utf-8" http-equiv="Content material-Sort">
    <meta content material="utf-8" http-equiv="encoding">
    <hyperlink href="" rel="stylesheet">
        h1 {
            font-family: 'Bebas Neue', cursive;
        .cart {
            width: 350px;
            background-color: rgb(210, 221, 231);
            border-radius: 10px;
            padding: 0px 10px 10px 10px;
            border: 1px cast lightgrey;
        .correct {
            flow: correct;
        #foreign money {
            margin-right: 5px;
            show: $dropdownDisplayCSS;
    <name>AppConfig Function Flag Demo Checkout Web page</name>
<frame onload="dropdownChanged()">
    <h1>FooBar Top class Plan Checkout</h1>
    <div elegance="cart">
        <h4>Buying groceries Cart</h4>
        FooBar Top class <span elegance="correct value"></span>
        <p identification="btc-discount">
                <small>Early adopter reduction, order the use of BTC via $bitcoinDiscountEndDate</small>
                <span elegance="correct">$bitcoinDiscountPercentage%</span>
            <span elegance="correct">
                <make a selection title="foreign money" identification="foreign money" onchange="dropdownChanged()" autocomplete="off">
                    <possibility worth="USD" $usdSelected>USD</possibility>
                    <possibility worth="BTC" $btcSelected>BTC</possibility>
                </make a selection>
                <span elegance="general"></span>
    serve as dropdownChanged() {
        foreign money = "USD"
        if ('$dropdownDisplayCSS' !== 'none') {
            foreign money = record.getElementById("foreign money").worth;
        if (foreign money === "USD") {
            value = 450; 
        } else {
            value = 0.000026;  
        if (reduction && foreign money === "BTC") {
            general = value - (value*reduction/100);
            general = general.toFixed(6);
            record.getElementById("btc-discount") = 'inherit';
        } else {
            general = value;
            record.getElementById("btc-discount") = 'none';
        record.querySelectorAll(".value").forEach(txt => { txt.textContent = currencySymbol+value; })
        record.querySelectorAll(".general").forEach(txt => { txt.textContent = currencySymbol+general; })
    html = Template(html_template).exchange(
    go back html

elegance SimpleCheckoutPageWebServer(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_header("Content material-type", "textual content/html")
        self.wfile.write(bytes(get_html(), "utf-8"))

if __name__ == "__main__":
    hostname = "localhost"
    webServer = HTTPServer((hostname, WEBSERVER_PORT), SimpleCheckoutPageWebServer)
    url = f"http://{hostname}:{WEBSERVER_PORT}"
    print(f"Native webserver began. To view, navigate your browser to: {url}"), new=2)
    check out:
    with the exception of KeyboardInterrupt:

Run the script the use of Python and it must get started a neighborhood webserver, question AppConfig in your configuration, and open a web page for your browser that displays a ridicule checkout web page.

The sample Python app. It shows a demo checkout screen in US dollars.

There’s no connection with bitcoin being an possibility but as a result of we haven’t enabled that function so let’s achieve this. Go away the checkout web page open in a tab and return to AppConfig. Permit your flag the use of the slider at the correct and remember to’ve created the 3 attributes proven within the screenshot. Then save and deploy similar to you probably did remaining time.

The AWS AppConfig console sample feature flag with additional attributes.

AWS AppConfig console. This image shows how to deploy configuration.

Now return in your tab with the checkout web page and reload the browser. Prior to each and every web page load our little webserver gets the most recent configuration from AppConfig and render the web page accordingly. When the web page reloads, you’ll be able to see that we’ve now enabled Bitcoin as an possibility purely thru a configuration exchange with no need to deploy new code.

The sample Python app. After deploying the feature flag, this image now shows a demo checkout screen using Bitcoin.

The usage of function flags in Lambda

We not too long ago launched an more uncomplicated option to name function flags in Lambda, The usage of the AWS AppConfig Lambda extension, you’ll be able to simply name a unmarried flag or a couple of flags to have the facility of function flagging in a Lambda serve as. The arrange procedure for function flags utilized in Lambda is equal to above, however you’ll be able to use the extension to get flag information. Seek the advice of this documentation to peer methods to name function flags in Lambda.

About CloudWatch Plainly

If you have an interest in A/B trying out for function optimization, chances are you’ll imagine Amazon CloudWatch Plainly. Whilst AWS AppConfig Function Flags are extra suited for function releases with out optimization, CloudWatch Plainly provides you with in depth information about two permutations of your tool and the way they evaluate with regards to efficiency. You’ll learn extra right here.


The usage of function flags may also be transformative in the way you expand and liberate tool. As a substitute of the danger of pushing new code to 100% of your customers on release day, you’ll be able to use function flags to deploy code early, however have it hidden at the back of a function flag configuration. On release day, simply turn the function flag with out pushing out new code. AWS AppConfig Function Flags allow you to roll out options safely the use of flag constraints to ensure unintentional flag values don’t get launched. Flags may also be rolled out regularly to restrict blast radius; if one thing is going improper, AWS AppConfig can robotically roll again your function flags instantly. Moreover, after you might be performed with a short lived flag, AWS AppConfig is helping you blank them up and deprecate the ones flags.

Get began with AWS AppConfig Function Flags and be told extra about AWS AppConfig.

Ivan Garcia: Ivan is a tool engineer at AWS AppConfig the place he enjoys making tool this is protected, simple to make use of, and protected in opposition to human error. He’s a former member of AWS’s safety staff the place he helped expand era round computerized safety trying out of the AuthN/AuthZ implementations of AWS services and products. Prior to becoming a member of AWS Ivan labored for 10 years at CGI Federal, partnering carefully with Medicare’s Phase A auditors to assist streamline and automate the Medicare Audit and Compensation procedure for American hospitals. Ivan has a B.S from Carnegie Mellon College and because the father of a child his spare time activities come with peek-a-boo, being chased, and no longer getting sufficient sleep.


Steve Rice: Steve has a occupation that spans each Product and Engineering management. He has led leading edge merchandise at firms like Amazon, Coca-Cola, LivingSocial, and AOL.  At AWS, Steve leads AWS AppConfig, which is a carrier that permits engineering groups to transport quicker and extra safely the use of steady configuration and have flags. Steve has been a speaker at many meetings, together with re:Invent and the Atlassian Group convention. He’s primarily based within the Washington DC house and has a super-smart spouse, 3 beautiful children, and a couple of incontinent canines.


Leave a Reply

Your email address will not be published. Required fields are marked *

Previous post AWS Batch for Amazon Elastic Kubernetes Carrier
Next post Accelerating innovation in Thailand with the AWS Asia Pacific (Bangkok) Area