Create AWS CloudWatch Evidently Segments

The aws:evidently/segment:Segment resource, part of the Pulumi AWS provider, defines CloudWatch Evidently segments that filter users or sessions based on attribute matching rules. This resource is deprecated; AWS recommends using AppConfig feature flags instead. This guide focuses on two capabilities: pattern-based filtering and segment documentation.

Segments are standalone filters referenced by Evidently features and launches. The examples are intentionally small. Combine them with your own Evidently projects and feature flags.

Define a segment with a pattern rule

CloudWatch Evidently segments filter users or sessions based on attribute rules, allowing teams to target feature flags or experiments to specific audiences.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.evidently.Segment("example", {
    name: "example",
    pattern: "{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
    tags: {
        Key1: "example Segment",
    },
});
import pulumi
import pulumi_aws as aws

example = aws.evidently.Segment("example",
    name="example",
    pattern="{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
    tags={
        "Key1": "example Segment",
    })
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/evidently"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := evidently.NewSegment(ctx, "example", &evidently.SegmentArgs{
			Name:    pulumi.String("example"),
			Pattern: pulumi.String("{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}"),
			Tags: pulumi.StringMap{
				"Key1": pulumi.String("example Segment"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var example = new Aws.Evidently.Segment("example", new()
    {
        Name = "example",
        Pattern = "{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
        Tags = 
        {
            { "Key1", "example Segment" },
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.evidently.Segment;
import com.pulumi.aws.evidently.SegmentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new Segment("example", SegmentArgs.builder()
            .name("example")
            .pattern("{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}")
            .tags(Map.of("Key1", "example Segment"))
            .build());

    }
}
resources:
  example:
    type: aws:evidently:Segment
    properties:
      name: example
      pattern: '{"Price":[{"numeric":[">",10,"<=",20]}]}'
      tags:
        Key1: example Segment

The pattern property defines the matching logic using JSON syntax. Here, the segment matches sessions where the Price attribute falls between 10 and 20. The name property creates a reusable identifier for referencing this segment in features and launches. Tags help organize segments across projects.

Add documentation to a segment

As segment libraries grow, teams add descriptions to document the business logic behind each audience filter.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.evidently.Segment("example", {
    name: "example",
    pattern: "{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
    description: "example",
});
import pulumi
import pulumi_aws as aws

example = aws.evidently.Segment("example",
    name="example",
    pattern="{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
    description="example")
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/evidently"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := evidently.NewSegment(ctx, "example", &evidently.SegmentArgs{
			Name:        pulumi.String("example"),
			Pattern:     pulumi.String("{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}"),
			Description: pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var example = new Aws.Evidently.Segment("example", new()
    {
        Name = "example",
        Pattern = "{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}",
        Description = "example",
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.evidently.Segment;
import com.pulumi.aws.evidently.SegmentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new Segment("example", SegmentArgs.builder()
            .name("example")
            .pattern("{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}")
            .description("example")
            .build());

    }
}
resources:
  example:
    type: aws:evidently:Segment
    properties:
      name: example
      pattern: '{"Price":[{"numeric":[">",10,"<=",20]}]}'
      description: example

The description property adds human-readable documentation explaining the segment’s purpose. This helps teams understand which audiences each segment targets without parsing the pattern syntax.

Beyond these examples

These snippets focus on specific segment features: pattern-based audience filtering and segment metadata and tagging. They’re intentionally minimal rather than full experimentation workflows.

The examples don’t require pre-existing infrastructure. They focus on configuring the segment as a standalone filter.

To keep things focused, common segment patterns are omitted, including:

  • Pattern syntax variations (numeric ranges, string matching, nested conditions)
  • Integration with Evidently projects, features, and launches
  • Segment usage tracking (experimentCount, launchCount outputs)

These omissions are intentional: the goal is to illustrate how segment filtering is wired, not provide drop-in experimentation modules. See the Evidently Segment resource reference for all available configuration options.

Let's create AWS CloudWatch Evidently Segments

Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.

Try Pulumi Cloud for FREE

Frequently Asked Questions

Deprecation & Migration
Should I use CloudWatch Evidently Segments for new projects?
No, this resource is deprecated. Use AWS AppConfig feature flags instead.
Configuration & Immutability
What properties can't I change after creating a segment?
The name, pattern, and description properties are immutable. Changing any of these forces resource replacement.
What region does my segment get created in?
Segments are created in the region specified by the region property, which defaults to your provider’s configured region.
Pattern Syntax
How do I format the pattern JSON string?
You can use either a single-line escaped JSON string like "{\"Price\":[{\"numeric\":[\">\",10,\"<=\",20]}]}" or a multi-line string with escaped quotes. Both formats are shown in the examples.
Usage & Monitoring
What do experimentCount and launchCount tell me?
These computed fields show how many experiments and launches currently use this segment, including those that aren’t running.

Using a different cloud?

Explore analytics guides for other cloud providers: