Create AWS CloudWatch Evidently Segments

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

Segments are reusable filters that can be referenced by Evidently experiments and launches. The examples are intentionally small. Note that this resource is maintained for backwards compatibility only.

Define a segment with a pattern rule

CloudWatch Evidently segments filter experiment participants based on attribute rules, allowing teams to target specific user groups or conditions.

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. In this example, the pattern filters for a “Price” attribute with numeric values greater than 10 and less than or equal to 20. The name property creates a unique identifier for the segment, and tags provide organizational metadata.

Add documentation to segment definitions

As segment libraries grow, descriptions help document the business logic behind pattern rules.

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 to explain the segment’s purpose. This helps teams understand the intent behind complex pattern rules when segments are referenced across multiple experiments or launches.

Beyond these examples

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

The examples don’t require pre-existing infrastructure. They focus on segment definition as standalone resources.

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

  • Pattern syntax variations (the examples show numeric comparisons only)
  • Integration with Evidently projects, experiments, or launches
  • Segment usage tracking (experimentCount, launchCount are output-only)

These omissions are intentional: the goal is to illustrate how segment patterns are 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
Is CloudWatch Evidently Segment still supported?
No, this resource is deprecated. Use AWS AppConfig feature flags instead for new projects.
Configuration & Immutability
What properties can't I change after creating a segment?
The name, pattern, and description properties are immutable. Changing any of these requires recreating the segment.
How do I format JSON in the pattern field?
The pattern field accepts a JSON string. You can use inline JSON with escaped quotes like {\"Price\":[{\"numeric\":[\">\",10]}]} or multi-line formatted JSON with proper escaping.
Where can I learn about segment pattern syntax?
Pattern syntax is documented in the AWS CloudWatch Evidently segment rule pattern syntax guide, linked in the pattern property description.

Using a different cloud?

Explore analytics guides for other cloud providers: