Perform A/B testing and dark launches of your IoT applications using AWS IoT Core and Amazon CloudWatch Evidently
For IoT teams, the key architectural takeaway is the separation of control and data planes. AWS IoT Core device shadows act as the device-state control surface, while MQTT telemetry and CloudWatch Evidently handle the measurement path. That split matters because feature rollout, observability, and device behavior are no longer tightly coupled inside firmware alone; they can be coordinated centrally without changing the device communication model.
The integration pattern also highlights a practical compromise: feature decisions are evaluated in the cloud, but execution still happens at the edge through conditional device logic. This keeps the rollout mechanism lightweight and interoperable, yet it also means device code must remain disciplined about how it reads, stores, and applies the desired flag state. In production, that creates versioning, idempotency, and retry concerns around shadow updates and telemetry delivery that are easy to overlook during a demo.
From an operations perspective, the real value is release governance. Experiments and dark launches give product and platform teams a way to validate behavior before broader exposure, but the workflow only works if metrics are meaningful and consistent across devices. The custom KPI design is therefore an architectural decision, not just an analytics one: choose signals that genuinely reflect feature impact, or the experiment will produce confident but unusable answers.
For fleet operators, indexing shadow state turns rollout data into an operational query surface. That enables targeting, reporting, and follow-up actions against cohorts of devices with specific feature states. The trade-off is added platform dependency: the more you rely on shadow-based orchestration, the more important naming conventions, index configuration, and lifecycle cleanup become to maintainability at fleet scale.
Solution overview
This is a fully serverless solution consisting of AWS IoT Core, Lambda and Evidently. The design uses a pub-sub model based on the lightweight MQTT protocol for frontend integration with IoT devices. This approach maximizes interoperability and abstracts the feature management capabilities provided by Evidently. The AWS IoT Core device shadow service is used to store device state, and house the current (reported) and expected (desired) feature flag statuses in the cloud.
Once the solution is deployed, Evidently is used to run experiments and launches.
Figure 1: Solution architecture
- IoT application developers develop and release new features. Their objective is to ensure that their code delivers business value. IoT application developers are looking for answers to questions such as โwhich of the newly activated machine learning models successfully reduces the number of human adjustments made on the smart thermostat over the past 24 hours and therefore leads to a better customer experience?โ
- IoT fleet managers monitor technical characteristics of IoT devices. They gather operational insights into the deployed devices, including their current firmware versions and feature sets. IoT fleet managers are looking for answers to questions such as โwhich smart thermostats owned by our customers have a specific machine learning feature currently activated?โ
How the solution works
- An AWS IoT Core device (
myDevice) subscribes to an AWS IoT Core reserved topic ($aws/things/myDevice/shadow/name/myFeatures/update/accepted) so that it is actively notified of successful updates made to the deviceโs named shadow (myFeatures). This mechanism instructs the IoT device of its desired feature flag status through the lightweight MQTT protocol. - The device periodically publishes a message to an AWS IoT Core topic (
myApp/myDevice/myFeatures). This MQTT telemetry payload in JSON format consists of the current feature flag status (myFeature) and a custom metric (myMetric). The custom metric is a key performance indicator (KPI) for the feature. For example, with a smart thermostat, a meaningful KPI we could monitor and aim to drive down would be the number of manual human adjustments made over the past 24 hours. Depending on the objectives of the release, the KPIs could track multiple other measurable characteristics, such as battery drain rate, user satisfaction score, or average daily use. - Every message published to this topic invokes a Lambda function through a configured AWS IoT Core rule and corresponding action.
- The Lambda function calls the Evidently
EvaluateFeatureAPI, using the deviceโs thing name (myDevice) as theentityId. This returns the deviceโs desired feature flag, determined by the Evidently service. The function also uses thePutProjectEventsAPI to submit the custom metric for use in an Evidently experiment. Evidently encrypts data at rest by default using AWS owned keys. Refer to How CloudWatch Evidently collects and stores data to learn how Evidently secures metadata about projects, features, launches and experiments, as well as metric events and evaluation data. - The Lambda function also updates the deviceโs JSON named shadow object in AWS IoT Core to reflect the
reportedanddesiredfeature flag values. - After the successful update of the deviceโs named shadow, a new message is automatically published to the reserved topic by AWS IoT Core (
$aws/things/myDevice/shadow/name/myFeatures/update/accepted). This is received by the device through its subscription. - The device stores the desired feature flag value and activates the local code associated with the feature using a conditional statement.
| MQTT topic | MQTT action by device | Description |
|---|---|---|
| myApp/myDevice/myFeatures | Publish | Topic used by the device to publish telemetry information. |
| $aws/things/myDevice/shadow/name/myFeatures/update/accepted | Subscribe | Reserved topic used by the device to subscribe to AWS IoT Core device shadow updates. |
- IoT application developers will create an Evidently project, feature and experiment. After starting the experiment, they can monitor its performance using custom metrics and make informed decisions about its effectiveness through A/B testing. Once satisfied with the results, they can launch the chosen feature across the device fleet in a controlled manner.
- AWS IoT Core fleet indexing is configured by IoT fleet managers to index and query the named shadows. This is done to create reports of the
reportedfeature flag values of the IoT devices.
Deploying the solution
An AWS CloudFormation template has been provided to deploy all AWS resources required by this solution. The template also provisions a single AWS IoT Core device so that you can manually simulate its interaction with Evidently.Prerequisites
For this walkthrough, you should have the following prerequisites in place:- An AWS account
- AWS IAM permissions to deploy the AWS resources using the CloudFormation template
- If you want to test this solution using your own IoT devices, you will be required to provision them separately using AWS IoT Core
Deploying the AWS CloudFormation template
To deploy the AWS IoT Core and Evidently environment described in this solution, we have provided a CloudFormation template which can be downloaded fromย our repository. This file should be downloaded to your local machine and deployed usingย CloudFormation. Navigate to the CloudFormation service in the AWS Console and from theย Stacksย page selectย Create stack โ With new resources (standard). Once theย Create stackย page is shown, verify that the AWS Region selected is where you want to deploy your resources. In addition, verify that all services leveraged by this solution are available in your chosen AWS Region. Service availability can be confirmed by reviewing theย AWS Regional Servicesย document. AWS Regional availability of the CloudWatch Evidently feature is listed in theย Perform launches and A/B experiments with CloudWatch Evidentlyย section of theย Amazon CloudWatch User Guide. Keep theย Prerequisite โ Prepare templateย setting asย Template is ready. In theย Specify templateย section select theย Upload a templateย file radio button and then selectย Choose file. In the file browser select the template that you just downloaded and selectย Next. On theย Specify stack detailsย page provide a uniqueย Stack nameย (such asยmyIoTApp) and then update the default values for the parameters where necessary:
thingNameย (default:ยmyDevice) โ the naming suffix of the AWS IoT Core devicevariantModelBaselineย (default:ยModelBaseline) โ the name of the baseline model used within EvidentlyvariantModelVariantAย (default:ยModelVariantA) โ the name of the first model variant used within EvidentlyvariantModelVariantBย (default:ยModelVariantB) โ the name of the second model variant used within Evidently
Figure 2: Specifying CloudFormation stack details
CREATE_COMPLETEย it has been fully deployed. Theย Outputsย tab will include the following values that are required for testing. The stack creation will take approximately 3 minutes.
outputPublishToThisTopicย ([Stack name]/[Stack name]-EvidentlyIoT-[thingName]/myFeatures) โ MQTT topic for this test device to subscribe to.outputSubscribeToThisTopicย ($aws/things/[Stack name]-EvidentlyIoT-[thingName]/shadow/name/myFeatures/update/accepted) โ Reserved MQTT topic for the test deviceโs named shadow which the device will subscribe to. AWS IoT Core publishes a JSON response state document to this topic when it accepts a change to the deviceโs named shadow.outputThingNameย ([Stack name]-EvidentlyIoT-[thingName]) โ Thing name prefix used for devices. This is also the name of the test device.
Figure 3: Reviewing the CloudFormation stack output
Interacting with the solution using a single test device
The MQTT test client in AWS IoT Core will be used to simulate a single IoT deviceโs interaction with the solution. Navigate to theย AWS IoT Core homepageย in the AWS Console and selectย Test > MQTT test clientย from the left menu. In theย Topic filterย text box of theย Subscribe to a topicย tab, enter the value from theยoutputSubscribeToThisTopicย CloudFormation output and then selectย Subscribe. You should now see your subscription in theย Subscriptionsย list.
Figure 4: Subscribing to a topic
outputPublishToThisTopicย CloudFormation output.
To simulate the publishing of a payload to the telemetry topic, the message should contain bothย myFeatureย andย myMetricย key-value pairs. An example payload is shown below.
{
"myFeature": "ModelBaseline",
"myMetric": 5
}
Enter this JSON payload into theย Message payloadย text box and then selectย Publish.
Figure 5: Simulating publishing of a payload to the telemetry topic
myFeatureย value simulates the device reporting which feature is currently in use, while theย myMetricย value is used to report the custom metric.
The MQTT test client will return the contents of the named shadowโsย JSON shadow document.
Figure 6: Named shadow contents
desiredย value in the response is the feature flag that Evidently has allocated to this AWS IoT Core device. This will always be the default variant until the Evidently experiment starts. Theย reportedย value will match the value published previously through theย Message payloadย during the test.
Device-side handling of feature information
In a real-life IoT application running on a device, its code would be required to process the receivedย["desired"]["myFeature"]ย key-value to enact the logic required to activate the feature.
Example device-side code is shown below:
if state["desired"]["myFeature"] == "ModelBaseline":
print("This is my Baseline code!")
# TODO: Baseline Model routine
elif state["desired"]["myFeature"] == "ModelVariantA":
print("This is my Model Variant A code!")
# TODO: Model Variant A routine
elif state["desired"]["myFeature"] == "ModelVariantB":
print("This is my Model Variant B code!")
# TODO: Model Variant B routine
# TODO: Code to publish the myFeature value back as telemetry with the reported value
Running the Amazon CloudWatch Evidently experiment
The CloudFormation template created an Evidently project which already has the feature and experiment configured. The experiment initially has a status ofยCreated. For Evidently to start allocating feature variants the Experiment must be started.
To start the experiment, first navigate toย CloudWatch > Application monitoring >ย Evidentlyย in the AWS Console. Underย Projectsย you will see the project that has been created for you with the nameย [Stack name]-myEvidentlyProject. Select the project name to be taken to theย Projectย page.
Select theย Experimentsย tab, where you will see the experiment that has been created for you with the nameย [Stack name]-myEvidentlyExperiment. Select the experiment name to be taken to theย Experimentย page. Now select theย Start experimentย option under theย Actionsย menu to start your experiment.
Figure 7: Starting the Evidently experiment
Figure 8: Setting the Evidently experiment schedule end date
Deploying the load generator
To allow you to view meaningful results from a simulated experiment, we have provided a separate load generator solution that provisions 50 AWS IoT Core things. The template for the load generator can be downloaded fromย our repositoryย and identical steps should be taken to the previous stack deployment to upload the file ready for deployment. On theย Specify stack detailsย page, provide a unique name for you stack (such asยmyIoTAppLoadGen). The template will request 2 parameters which will be used to create the CloudFormation stack and configure the resources:
deviceCountย (default:ย50) โ the number of devices expected by the load generator Lambda function. Note that the provided CloudFormation template always creates 50 AWS IoT device objects but the Lambda code will only generate load for the number of devices specified in this parameter.loadIntervalย (default:ย1) โ the frequency in minutes that the load generator Lambda function is invoked. For real-life IoT use cases, this value may be higher to reflect less frequent exchanges of information about the deviceโs feature flag.stackNameย โ the name of the CloudFormation stack deployed earlier which houses your AWS IoT Core and Evidently solution. This is used to find resources created by the previous stack.
Figure 9: Inputting CloudFormation stack load generator parameters
CREATE_COMPLETE.
Using the load generator
The deployed CloudFormation stack has anย Amazon EventBridgeย schedule that triggers a Lambda function to execute at the frequency entered in theยloadIntervalย parameter (by default every 1 minute). As Lambda functions are stateless and short-lived, this code simulates device behavior by interacting directly with the AWS IoT Core service using the AWS SDK over HTTPS, and not using MQTT. The function also emits arbitrary metrics from ranges centered on baselines of 5 (baseline model), 8 (model A) and 3 (model B) to replicate how the device might respond to the activation of the 2 machine learning model variants. These values were chosen to intentionally demonstrate better and worse performing variants during the experiment.
To view the results of your experiment, navigate back to the experiment in Evidently, and select theย Resultsย tab. This page may take up to the number of minutes specified in theย loadIntervalย parameter to populate as we wait for the EventBridge rule to trigger. If you are still not seeing any results, make sure that the time frame in the top right corner of the page is set to a range that covers your experiment.
You will notice that not all columns in the table or graphs are fully populated initially. For these statistical calculations to be populated, at least 100 events need to have been recorded by Evidently for all variations. It will take approximately 7 executions of the load generator Lambda function for the statistical values to be populated. This will be approximately 8 minutes with the default for theย loadIntervalย parameter.
Below is an example of what the experiment results look like when these 50 devices are configured to interact with the solution over 4 days.
Evidently has concluded thatย ModelVariantBย is better performing, and therefore is better suited for wider adoption.
Figure 10: Reviewing Evidently experiment results
ModelVariantB.
Launching the feature
As an IoT application developer, once you are happy with the experiment, you can launch the most successful variant to make it permanently live. Before launching a feature, check that your experiment has completed or that running experiments have been cancelled. This is required to ensure that the experiment and launch do not interfere with one another. To launch a feature, first navigate toย Evidentlyย and select your project ([Stack name]-myEvidentlyProject) from the list of projects. Once in theย Projectย page, select theย Launchesย tab. Select theย Create launchย button. Theย Create feature launchย page will be displayed.
In theย Launch nameย text box, give your launch a name (such asย myIoTApp-myEvidentlyLaunch), and optionally provide a description. Make sure theย Select from existing featuresย option is chosen and that the required feature ([Stack name]-myEvidentlyFeature) is selected from theย Feature nameย drop down.
In our example we would like to launch the feature in 5 steps to incrementally shift all of our devices to the best performing feature at 4-hour intervals. If you would like to see the results of the launch more quickly, then reduce the increment between the steps described below from 4 hours to a duration appropriate for your testing.
In theย Launch configurationย section, select theย Schedule launchย option. Underย Schedule step 1ย enter aย Step Dateย andย Step Timeย in the future, then in theย Traffic percentageย allocate 100% of the traffic to theย ModelBaselineย variant. Disable theย Excludeย selector for theย ModelVariantAย variant, and then allocate 0% of the traffic to theย ModelVariantBย variant.
Figure 10: Setting up first Evidently launch step
ModelBaselineย Traffic percentage by 25% and increasing the ModelVariantB Traffic percentage by 25%. Repeat these steps 4 more times until all of the expected traffic has been allocated toย ModelVariantB.
Select theย Create launchย button.
Figure 11: Configuring steps for the Evidently launch
Figure 12: Reviewing the Evidently launch configuration steps
Figure 13: Monitoring an Evidently launch
Identifying devicesโ feature flags using AWS IoT Core fleet indexing
As an IoT fleet manager, you can use AWS IoT Core fleet indexing to query the attributes found in theยmyFeaturesย named shadow.
AWS IoT Core fleet indexing is a feature used to index, search, and aggregate your devicesโ data from multiple sources including device shadows. AWS IoT Core fleet indexing can also be used to createย dynamic thing groups, allowing certain AWS IoT Core functionality such as jobs and reporting to target devices with only the specific feature flag enabled. For example, you may want to target firmware updates only at devices that have a particular feature flag set.
In order to use this feature in AWS IoT Core, you will need toย turn on thing indexing for your named shadow. To do this, first navigate to theย AWS IoT Core Consoleย and then selectย Settingsย in the menu on the left. Scroll down to theย Fleet indexingย section and selectย Manage indexing.
Enable fleet indexing by selecting the switch at the top right of the page so the label readsย Activated. Now select theย Add named shadowsย tick box, then selectย Add shadow names. Enterย myFeaturesย in theย Shadow namesย text box and selectย Add. Finally selectย Updateย at the bottom of the page.
Figure 15: Turning on AWS IoT Core fleet indexing
myFeaturesย named shadow has been enabled, it is possible to run advanced thing searches to produce custom reporting based on the feature flagย reported.myFeatureย attribute.
To simulate an advance thing search from within theย AWS IoT Consoleย navigate toย Manage > All devicesย and thenย Thingsย from the menu on the left. Select theย Advanced searchย button on theย Thingsย page. In theย Queryย box enter:
shadow.name.myFeatures.reported.myFeature: "ModelVariantB"
Then selectย Search. This query can be saved for future use by using theย Save queryย button.
Figure 16: Performing an AWS IoT Core advanced thing search
ModelVariantB, which is approximately a third of the total number of devices. If the advanced thing search was performed after the completion of a launch, all the devices would be returned by this query.
Cleaning up
To avoid incurring future charges, delete the CloudFormation stacks that have been provisioned. If you have a running Evidently experiment or launch, you will need to stop these manually otherwise the stack deletion will fail.Conclusion
This post demonstrated how Evidently can be used with AWS IoT Core and Lambda to activate a feature flag embedded in your IoT application, measure the impact of the new feature using controlled experiments, and use this information to launch the feature more widely across your fleet of devices. About the authors:Alan Peaty
Alan is a Partner Solutions Architect helping Global Systems Integrators (GSIs) and their customers adopt AWS services. Prior to joining AWS, Alan worked as an architect at various systems integrators translating business requirements into technical solutions. Outside of work, Alan is a keen runner who loves to hit the muddy trails of the English countryside, and an Internet of Things (IoT) enthusiast.Pete Davis
Pete is Partner Solutions Architect working with a Global System Integrator in the Public Sector across EMEA. In previous roles, Pete has worked in the Publishing, Customer Communication and Marketing Execution industries in both the public and private sectors. In his spare time, Pete is keen follower of Formula 1 and MotoGP and is kept busy walking his familyโs four dogs.Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
