Skip to content

Feature Flags

The Feature Flags utility evaluates flags against caller-supplied context. It supports local rules in the Powertools for Python Flag Document format and AWS AppConfig multi-variant flags evaluated by the AppConfig Agent. See RFC discussion #5614 and feature request #3754 for the design and use cases.

Key features

  • Evaluate boolean or JSON-valued flags using request context, schedules, and numeric modulo ranges
  • Retrieve several flags with one Store call and an independent fallback for each flag
  • Validate results and fallbacks with caller-provided Standard Schema validators
  • Use AppConfig freeform documents, Agent-selected variants, or your own Store

When to use Feature Flags

Feature flags change application behavior without changing its code. A static flag has one value for every request. A dynamic flag uses rules to select a value for the current context, such as a customer's tier.

Use case Utility
Retrieve a static configuration value, with no rule evaluation Parameters, using getAppConfig or getConfig
Evaluate local rules against request context or the clock Feature Flags with a freeform Flag Document
Let AppConfig select a variant and its attributes Feature Flags with appConfigVariantStore

Getting started

Installation

Install the packages for the Store you use. Parameters and JMESPath are optional peers, so the core evaluator does not require either one.

1
npm install @aws-lambda-powertools/feature-flags
1
npm install @aws-lambda-powertools/feature-flags @aws-lambda-powertools/parameters @aws-sdk/client-appconfigdata
1
npm install @aws-lambda-powertools/feature-flags @aws-lambda-powertools/parameters
1
npm install @aws-lambda-powertools/jmespath

The envelope tab adds JMESPath to your chosen AppConfig installation. Agent-only imports do not load the AppConfigData SDK client.

Import path Exports Additional dependencies
@aws-lambda-powertools/feature-flags FeatureFlags, ruleEngineStore, errors, public types None
@aws-lambda-powertools/feature-flags/appconfig appConfigStore Parameters and @aws-sdk/client-appconfigdata
@aws-lambda-powertools/feature-flags/appconfig-agent appConfigAgentStore, appConfigVariantStore, disabledVariant Parameters, no SDK client
@aws-lambda-powertools/feature-flags/envelope search with Powertools JMESPath functions JMESPath
@aws-lambda-powertools/feature-flags/errors Error classes None
@aws-lambda-powertools/feature-flags/types Core API and Store types None

IAM permissions and the AppConfig Agent

Store Required function role permissions Required layer
appConfigStore appconfig:StartConfigurationSession, appconfig:GetLatestConfiguration None
appConfigAgentStore, appConfigVariantStore appconfig:StartConfigurationSession, appconfig:GetLatestConfiguration AWS AppConfig Agent Lambda extension

On the Agent path, the extension uses the function role to retrieve configuration. Attach the AWS AppConfig Agent Lambda extension layer for your region and architecture.

Multi-variant Agent version

appConfigVariantStore requires AppConfig Agent Lambda extension version 2.0.678 or later, the first release that supports multi-variant flags. Check the extension version in the layer you deploy.

Prefetch configuration

Set AWS_APPCONFIG_EXTENSION_PREFETCH_LIST to your configuration path, such as /applications/my-app/environments/prod/configurations/features, to reduce cold-start latency. See the Agent configuration options.

Evaluating a single flag

Create a Store and pass it to FeatureFlags. The local Store below evaluates checkout_v2 for premium customers. The context is optional; the utility does not read facts from the event or environment for you.

Evaluate a local rule
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';

const document = {
  checkout_v2: {
    default: false,
    rules: {
      premium_customers: {
        when_match: true,
        conditions: [{ action: 'EQUALS', key: 'tier', value: 'premium' }],
      },
    },
  },
};

const flags = new FeatureFlags({
  store: ruleEngineStore({ source: async () => document }),
});

export const handler = async () =>
  flags.evaluate({
    name: 'checkout_v2',
    context: { tier: 'premium' },
    default: false, // (1)!
  });
  1. This is the caller's fallback for a missing flag or an availability failure. It does not override the Flag Document's default.

evaluate requires a default fallback. It returns that fallback when the flag is missing or the Store is unavailable, never undefined. If the flag exists but no Rule matches, it returns the Flag Document's default, not the caller's fallback.

Fallback without a schema Result type Runtime check on a found value
Boolean boolean, not a boolean literal type Must be a boolean
Number number, not a number literal type Must be a number
String string, not a string literal type Must be a string
Object, array, or null JSONValue No structured type inferred from the fallback

A primitive type mismatch throws FlagValueTypeError. Use a schema when you need a checked structured result type. Variant Stores instead require and return a full Variant.

Evaluating several flags

Pass flag names and their fallbacks in flags. evaluateMany calls Store.getMany once and applies the fallback independently for each missing flag. Any configuration, operand, or result-validation error throws for the whole batch. It does not return partial results after an error.

Evaluate a batch with independent fallbacks
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';

const flags = new FeatureFlags({
  store: ruleEngineStore({
    source: async () => ({
      checkout_v2: { default: true },
      limit: { default: 20, boolean_type: false },
    }),
  }),
});

export const handler = async () => {
  const result = await flags.evaluateMany({
    flags: { checkout_v2: false, limit: 10, banner: 'none' },
    context: { tier: 'premium' },
  });
  // { checkout_v2: true, limit: 20, banner: 'none' }
  return result;
};

Getting enabled features

getEnabledFeatures calls Store.getAll once and returns enabled flag names in Store order. It omits missing flags and returns [] on an availability failure.

List enabled flag names
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import document from './flagDocument.json' with { type: 'json' };

const flags = new FeatureFlags({
  store: ruleEngineStore({ source: async () => document }),
});

export const handler = async () =>
  flags.getEnabledFeatures({ context: { tier: 'premium' } });
// ['checkout_v2', 'ten_percent_off_campaign']

Advanced

Flag Document format

The local rule engine uses the Powertools for Python freeform JSON shape. Store it in an AppConfig freeform configuration profile, or return it from any asynchronous source. AppConfig's feature flag profiles use a different format and need the Variant Store.

Boolean and static flags
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "checkout_v2": {
    "default": false,
    "rules": {
      "premium_customers": {
        "when_match": true,
        "conditions": [
          { "action": "EQUALS", "key": "tier", "value": "premium" }
        ]
      }
    }
  },
  "ten_percent_off_campaign": { "default": true }
}
Field Meaning
default Required Flag Default when no Rule matches
boolean_type Optional boolean, defaults to true. Set false for non-boolean default or when_match values
rules Optional object keyed by Rule name. The first matching Rule wins
when_match Required result of a matching Rule
conditions Required non-empty array of Conditions within each Rule, joined with logical AND
action, key, value Required Condition fields. key identifies a context fact or a fixed schedule key

With boolean_type: false, a flag can return any JSON value, including arrays and objects.

A non-boolean flag
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "premium_features": {
    "boolean_type": false,
    "default": [],
    "rules": {
      "premium_customers": {
        "when_match": ["no_ads", "no_limits", "chat"],
        "conditions": [
          { "action": "EQUALS", "key": "tier", "value": "premium" }
        ]
      }
    }
  }
}

Actions

In this table, a is the context value at key and b is the Condition's value. Schedule Actions use the clock instead of context.

Action Meaning Operand types
EQUALS a equals b using strict deep JSON equality Any supported context value and JSON value
NOT_EQUALS a does not equal b Any supported context value and JSON value
KEY_GREATER_THAN_VALUE a > b Two numbers or two strings
KEY_GREATER_THAN_OR_EQUAL_VALUE a >= b Two numbers or two strings
KEY_LESS_THAN_VALUE a < b Two numbers or two strings
KEY_LESS_THAN_OR_EQUAL_VALUE a <= b Two numbers or two strings
STARTSWITH a starts with b Two strings
ENDSWITH a ends with b Two strings
IN, KEY_IN_VALUE a is in b b is an array, object, or string. See membership rules below
NOT_IN, KEY_NOT_IN_VALUE a is not in b Same as IN
VALUE_IN_KEY b is in a a is an array or string within the public context contract
VALUE_NOT_IN_KEY b is not in a Same as VALUE_IN_KEY
ALL_IN_VALUE Every element of a is in b Two arrays
ANY_IN_VALUE At least one element of a is in b Two arrays
NONE_IN_VALUE No element of a is in b Two arrays
SCHEDULE_BETWEEN_TIME_RANGE Current time is within inclusive bounds Key CURRENT_TIME; object with START, END in HH:MM, optional TIMEZONE
SCHEDULE_BETWEEN_DATETIME_RANGE Current wall-clock datetime is within inclusive bounds Key CURRENT_DATETIME; object with timezone-naive ISO8601 START, END, optional TIMEZONE
SCHEDULE_BETWEEN_DAYS_OF_WEEK Current day is in DAYS Key CURRENT_DAY_OF_WEEK; object with uppercase day-name array DAYS, optional TIMEZONE
MODULO_RANGE Remainder of a divided by BASE is within inclusive bounds Numeric a; object with integer BASE, START, END

Membership follows Python's in semantics, with strict JSON equality:

Container Membership test Needle types
Array Compare against each element Any JSON value
Object Check own keys, not values Strings match keys. Numbers, booleans, and null do not match; arrays or objects throw
String Check for a substring by Unicode code point String only

Objects can be Condition values, but not context values. For an empty context array, ALL_IN_VALUE and NONE_IN_VALUE match, while ANY_IN_VALUE does not.

Evaluation semantics

Local contexts accept strings, numbers, booleans, and flat arrays of those values. Nested objects, nested arrays, null, and undefined throw InvalidContextError. The Variant Store has stricter context restrictions.

Rule Behavior
Rule priority Evaluate in document order; return the first matching Rule's when_match
Rule names Reject empty names and array-index names such as "10", because JavaScript would reorder them. Use names such as rule_10
Conditions All Conditions must match. Evaluation short-circuits at the first non-match
Missing context key Never matches, including negative Actions. Schedule Actions ignore caller context
Equality Strict JSON comparison. Booleans never equal numbers; arrays compare in order; object key order does not matter
Strings Order, prefixes, suffixes, and substrings use Unicode code points
Incompatible operands Throw ConditionEvaluationError, identifying the flag, Rule, key, and Action without values
Local enabled Use Python-style JSON truthiness: false, 0, "", null, empty arrays, and empty objects are disabled
Variant enabled Use the Agent response's explicit boolean field

Non-empty arrays and objects are enabled, regardless of their contents. This differs from JavaScript's built-in truthiness for empty containers. getEnabledFeatures uses each Store result's enabled field, not its value's type.

Time-based flags

Set the schedule Condition's fixed key and bounds in the document. TIMEZONE defaults to UTC and accepts named IANA zones, not fixed-offset strings. Day names run from MONDAY through SUNDAY.

Time, datetime, and day-of-week schedules
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
  "happy_hour": {
    "default": false,
    "rules": {
      "evening_in_rome": {
        "when_match": true,
        "conditions": [
          {
            "action": "SCHEDULE_BETWEEN_TIME_RANGE",
            "key": "CURRENT_TIME",
            "value": {
              "START": "17:00",
              "END": "19:00",
              "TIMEZONE": "Europe/Rome"
            }
          }
        ]
      }
    }
  },
  "holiday_sale": {
    "default": false,
    "rules": {
      "december_campaign": {
        "when_match": true,
        "conditions": [
          {
            "action": "SCHEDULE_BETWEEN_DATETIME_RANGE",
            "key": "CURRENT_DATETIME",
            "value": {
              "START": "2026-12-25T12:00:00",
              "END": "2026-12-31T23:59:59",
              "TIMEZONE": "America/New_York"
            }
          }
        ]
      }
    }
  },
  "weekend_discount": {
    "default": false,
    "rules": {
      "weekend_in_new_york": {
        "when_match": true,
        "conditions": [
          {
            "action": "SCHEDULE_BETWEEN_DAYS_OF_WEEK",
            "key": "CURRENT_DAY_OF_WEEK",
            "value": {
              "DAYS": ["SATURDAY", "SUNDAY"],
              "TIMEZONE": "America/New_York"
            }
          }
        ]
      }
    }
  }
}
Evaluate a scheduled flag
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import document from './scheduleDocument.json' with { type: 'json' };

const flags = new FeatureFlags({
  store: ruleEngineStore({ source: async () => document }),
});

export const handler = async () =>
  flags.evaluate({ name: 'happy_hour', default: false });
Schedule behavior Result
Time bounds Inclusive, including the entire start and end minutes
End time before start time Range crosses midnight, such as 23:30 to 01:00
Datetime bounds Timezone-naive ISO8601 values. Set TIMEZONE separately; do not append Z or an offset
Daylight saving time Compare wall-clock fields, matching Python. Both occurrences of a repeated fall-back time can match; spring-forward gaps do not become another time
Reversed datetime bounds Valid document, but the Condition never matches
Clock Read once per local Store call, after retrieval and validation, shared by all flags and Conditions in that call

Use ruleEngineStore({ now }) to test schedule boundaries without changing the system clock.

Modulo ranges

MODULO_RANGE divides a numeric context value by BASE and compares the remainder with START and END. All three bounds must be integers and satisfy 0 <= START <= END <= BASE - 1. The bounds are inclusive.

Select buckets 0 through 19
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "checkout_v2": {
    "default": false,
    "rules": {
      "first_twenty_buckets": {
        "when_match": true,
        "conditions": [
          {
            "action": "MODULO_RANGE",
            "key": "customer_id",
            "value": { "BASE": 100, "START": 0, "END": 19 }
          }
        ]
      }
    }
  }
}
Supply a numeric customer identifier
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import document from './moduloDocument.json' with { type: 'json' };

const flags = new FeatureFlags({
  store: ruleEngineStore({ source: async () => document }),
});

export const handler = async () =>
  flags.evaluate({
    name: 'checkout_v2',
    context: { customer_id: 12345 },
    default: false,
  });

The Action uses Python remainder semantics, not JavaScript % alone. With BASE: 10, -1 has remainder 9; fractional contexts also work. Boolean contexts throw ConditionEvaluationError, and boolean bounds fail document validation. This Action does not hash identifiers or reproduce AppConfig's traffic-splitting algorithm.

Validating results with Standard Schema

Pass a Standard Schema validator in schema for evaluate, or a per-flag schemas map for evaluateMany. Install the validator library you choose. The utility does not bundle a validator.

Validate structured values and transform a date with Zod
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import { z } from 'zod';

const flags = new FeatureFlags({
  store: ruleEngineStore({
    source: async () => ({
      settings: { default: { theme: 'dark', limit: 10 }, boolean_type: false },
      launch_date: { default: '2026-12-01T00:00:00Z', boolean_type: false },
    }),
  }),
});
const settingsSchema = z.object({
  theme: z.enum(['light', 'dark']),
  limit: z.number(),
});
const dateSchema = z.iso.datetime().transform((value) => new Date(value));

export const handler = async () => {
  const settings = await flags.evaluate({
    name: 'settings',
    default: { theme: 'light', limit: 5 },
    schema: settingsSchema,
  });
  // settings is { theme: 'light' | 'dark'; limit: number }.
  const result = await flags.evaluateMany({
    flags: {
      settings: { theme: 'light', limit: 5 },
      launch_date: '2026-01-01T00:00:00Z',
    },
    schemas: { settings: settingsSchema, launch_date: dateSchema },
  });
  // result.launch_date is a Date, including when the fallback is used.
  return { settings, result };
};

The evaluator validates fallbacks before calling the Store. It returns the schema's validated output for both found values and fallbacks. A schema replaces the primitive type check and supplies the inferred result type. Transforms can return non-JSON values, such as Date.

Schemas must never produce undefined. TypeScript rejects such output types; runtime validation throws FlagResultValidationError if a validator still returns undefined. Validation issues also throw this error, whose message lists issue paths without validator messages or values. If a validator throws, the error wraps the thrown value as its cause. Do not log the cause if it can contain sensitive values.

Choosing a Store

Store Source format Evaluation and retrieval cache
ruleEngineStore Python-format Flag Document from any async source Local evaluation; source controls retrieval caching
appConfigStore AppConfig freeform Flag Document Local evaluation; Parameters caches retrieval
appConfigAgentStore AppConfig freeform Flag Document Local evaluation; Agent caches retrieval and polls
appConfigVariantStore AppConfig feature flag profile Agent evaluates, caches, and polls
Custom Store Your implementation's results Your implementation controls evaluation and retrieval

Local rule engine

ruleEngineStore({ source, now?, logger?, name? }) calls the asynchronous source on every Store call. The default Store name is rule-engine.

It validates the whole document and keeps the latest compiled snapshot. Unchanged serialized JSON content reuses validation, including a fresh equivalent object. Changed content or an in-place mutation triggers validation again. This is not a retrieval cache or a cache of evaluation results. An invalid replacement document throws rather than serving the previous document. Returned structured values are copies, so callers cannot mutate the cached snapshot.

Empty documents and empty rules objects are valid. With a Store logger, validation warns about them once per new document content.

AppConfig freeform Stores

Retrieve freeform flags with Parameters
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import { appConfigStore } from '@aws-lambda-powertools/feature-flags/appconfig';

// Install Parameters and the AppConfigData SDK client for this sub-path.
const store = appConfigStore({
  application: 'my-app',
  environment: 'prod',
  name: 'features',
  maxAge: 30,
});
const flags = new FeatureFlags({ store });
const checkoutV2 = await flags.evaluate({
  name: 'checkout_v2',
  context: { tier: 'premium' },
  default: false,
});
console.log(checkoutV2);
Retrieve freeform flags through the Agent
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';

// Install Parameters and attach the AppConfig Agent Lambda extension.
const store = appConfigAgentStore({
  application: 'my-app',
  environment: 'prod',
  name: 'features',
  timeout: 1000,
});
const flags = new FeatureFlags({ store });
const checkoutV2 = await flags.evaluate({
  name: 'checkout_v2',
  context: { tier: 'premium' },
  default: false,
});
console.log(checkoutV2);
Option SDK Store Agent freeform Store Description
name Required Required Configuration profile name or ID
environment Required Required Environment name or ID
application Optional Optional Application name or ID; defaults to POWERTOOLS_SERVICE_NAME
maxAge Optional Not supported Parameters retrieval cache duration in seconds. Default is POWERTOOLS_PARAMETERS_MAX_AGE, or 5 seconds
awsSdkV3Client Optional Not supported Supply an AppConfigData client
clientConfig Optional Not supported Configure a new SDK client. Ignored when awsSdkV3Client is supplied
timeout Not supported Optional Agent request timeout in milliseconds, default 3000
envelope, envelopeSearchFn Optional pair Optional pair Select an embedded Flag Document
logger Optional Optional Log local rule selection and document-validation warnings

The SDK Store creates one Parameters AppConfigProvider per Store. Agent Stores always call the Agent's local endpoint and do not add a retrieval cache.

Envelopes

When a configuration contains other settings, provide envelope and envelopeSearchFn together to select its Flag Document. An incomplete pair throws FeatureFlagsError at Store construction. A selection of null or undefined throws SchemaValidationError instead of using a fallback.

Select an embedded Flag Document
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
import { search } from '@aws-lambda-powertools/feature-flags/envelope';

// Select { checkout_v2: { default: true } } from a profile shaped like:
// { settings: { flags: { checkout_v2: { default: true } } } }
const store = appConfigAgentStore({
  application: 'my-app',
  environment: 'prod',
  name: 'configuration',
  envelope: 'settings.flags',
  envelopeSearchFn: search,
});
const flags = new FeatureFlags({ store });
const checkoutV2 = await flags.evaluate({
  name: 'checkout_v2',
  default: false,
});
console.log(checkoutV2);
Configuration with embedded flags
1
2
3
4
5
6
{
  "logging": { "level": "INFO" },
  "settings": {
    "flags": { "checkout_v2": { "default": true } }
  }
}

The search helper from /envelope includes the Powertools JMESPath functions, such as powertools_json. You can supply your own search function instead. Envelopes apply to freeform Stores, not Agent-selected Variants.

Custom Stores

A custom Store is a plain object with name, getMany, and getAll. Import Store and StoreResult from the core or /types entry point. No base class is required.

An in-memory Store
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {
  FeatureFlags,
  type Store,
  type StoreResult,
} from '@aws-lambda-powertools/feature-flags';

export const store: Store = {
  name: 'in-memory',
  getMany: async (names, _context) => {
    const results: [string, StoreResult][] = [];
    for (const name of names) {
      results.push([
        name,
        name === 'checkout_v2'
          ? { found: true, value: true, enabled: true }
          : { found: false },
      ]);
    }
    return Object.fromEntries(results);
  },
  getAll: async (_context) => ({
    checkout_v2: { found: true, value: true, enabled: true },
  }),
};

const flags = new FeatureFlags({ store });

export const handler = async () =>
  flags.evaluate({ name: 'checkout_v2', default: false });

Return { found: false } for missing flags and { found: true, value, enabled } for found flags. getMany receives the requested names and context; getAll receives context. Throw StoreUnavailableError for known availability failures so the evaluator can return fallbacks. Unexpected errors propagate. A custom source passed to ruleEngineStore must use the same error contract; the local engine does not classify source errors.

AppConfig multi-variant flags

appConfigVariantStore delegates rule evaluation to the Agent. It accepts name, environment, application, timeout, and logger, with the same retrieval defaults as the freeform Agent Store. It does not accept envelopes.

Evaluate Agent-selected Variants
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import {
  appConfigVariantStore,
  disabledVariant,
} from '@aws-lambda-powertools/feature-flags/appconfig-agent';

const flags = new FeatureFlags({
  store: appConfigVariantStore({
    application: 'my-app',
    environment: 'prod',
    name: 'features',
  }),
});

export const handler = async () => {
  const context = { email: 'jane@example.org', opted_in_to_beta: true };
  const ui = await flags.evaluate({
    name: 'ui_refresh',
    context,
    default: disabledVariant(),
  });
  const variants = await flags.evaluateMany({
    flags: { ui_refresh: disabledVariant(), checkout: disabledVariant() },
    context,
  });
  const enabledFeatures = await flags.getEnabledFeatures({ context });

  return {
    enabled: ui.enabled,
    attributes: ui.attributes,
    variants,
    enabledFeatures,
  };
};

FeatureFlags infers FeatureFlags<Variant> from this Store. Every fallback must be a full Variant, not false; every result is a Variant. Schemas are not supported on Variant-backed instances.

Variant field Meaning
enabled Explicit boolean returned by the Agent
variant Agent's _variant name, or default for basic flags without _variant
attributes Remaining response fields, excluding enabled and _variant. Values are strings, finite numbers, booleans, or flat arrays of those

disabledVariant() returns { enabled: false, variant: 'default', attributes: {} }. You can supply another valid Variant fallback. Basic flags retain their actual enabled field and attributes; missing attributes become {}.

For one requested flag in Lambda, the Store uses ?flag= and normalizes the unwrapped response. An empty successful single-flag response or a structured NoSuchFlag error means that flag is missing. For batches with several flags and for getEnabledFeatures, the Store fetches the whole profile once. This preserves independent fallbacks when a basic profile would reject a selective batch containing an unknown flag. A batch normalizes only requested flags, so an unrelated malformed flag does not fail the batch.

Variant context

Context requirement Supported values
Keys Match ^[A-Za-z_][A-Za-z0-9_.-]*$
Values Strings, finite numbers, or booleans
Unsupported Arrays, objects, null, undefined, and non-finite numbers

Invalid context throws InvalidContextError before retrieval. The Store passes context through Parameters getConfig's agentOptions. Parameters JSON-quotes strings and escapes non-ASCII characters in the Agent Context header. It preserves commas, quotes, whitespace, and newlines without percent-encoding values or permitting header injection. The freeform Agent Store evaluates context locally and does not inherit these Agent context restrictions.

Failure contract

The evaluator catches StoreUnavailableError, not every exception. Built-in AppConfig Stores classify known transport availability failures into this error.

Situation evaluate / evaluateMany getEnabledFeatures
Missing flag That flag's fallback Omit the flag
Timeout, connection failure, throttling or HTTP 429, service unavailability or HTTP 5xx Fallbacks; one evaluator warning if a logger is set []; one evaluator warning if a logger is set
Opaque Agent 5xx, including a hidden configuration failure Same availability fallback []
Access denied or authentication failure, including HTTP 401/403 Throw Throw
Missing application, environment, or configuration profile, including HTTP 404 Throw, not a missing-flag fallback Throw
Malformed document or response, invalid envelope, invalid context, or schema failure Throw Throw when applicable
Incompatible Condition operands or unexpected custom-Store error Throw for the whole call Throw

Opaque Agent errors

The Agent can hide a configuration failure behind an opaque 500 response. The utility treats it as unavailability. It throws for identifiable misconfiguration, but cannot recover a cause the Agent does not expose.

Let availability fallbacks work and handle other errors
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
import { FeatureFlagsError } from '@aws-lambda-powertools/feature-flags/errors';

const flags = new FeatureFlags({
  store: appConfigAgentStore({
    application: 'my-app',
    environment: 'prod',
    name: 'features',
  }),
});

export const handler = async () => {
  try {
    // Availability failures and missing flags return false without a catch.
    return await flags.evaluate({ name: 'checkout_v2', default: false });
  } catch (error) {
    if (error instanceof FeatureFlagsError) {
      // Report the category without logging values or the error cause.
      console.error({ category: error.name });
    }
    // Parameters errors and unexpected errors also propagate.
    throw error;
  }
};

All utility errors extend FeatureFlagsError. Import them from the core or /errors entry point.

Error When it is thrown
FeatureFlagsError Base error; also an incomplete envelope option pair
StoreUnavailableError Known availability failure from a Store; the evaluator catches it and returns fallbacks
SchemaValidationError Invalid Flag Document, invalid Variant response, or an envelope that selects no document
ConditionEvaluationError Incompatible local Action operands
InvalidContextError Unsupported context values, or invalid Variant context keys
FlagValueTypeError Found value differs from its primitive fallback type, or an invalid Variant fallback
FlagResultValidationError Standard Schema issues, a validator that throws, or an undefined schema output

Parameters retrieval, transformation, and configuration errors that are not availability failures propagate unchanged. They do not necessarily extend FeatureFlagsError. Search-function errors also propagate.

Logging

Pass an optional logger to FeatureFlags. For each completed call, the evaluator emits one debug entry with the outcome, such as found, partial, or fallback. A call that returns any fallbacks emits one warn entry with reason: 'missing' or reason: 'unavailable'. Several missing flags in a batch still produce one evaluator warning.

Log call outcomes without flag values
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ serviceName: 'checkout', logLevel: 'DEBUG' });
const flags = new FeatureFlags({
  logger, // One call-level outcome and, on fallback, one warning.
  store: ruleEngineStore({
    source: async () => ({ checkout_v2: { default: true } }),
    // Pass logger here too if you need per-flag rule selection logs.
  }),
});

export const handler = async () =>
  flags.evaluateMany({ flags: { checkout_v2: false, banner: 'none' } });

Store loggers are separate. A local Store logger emits per-flag debug entries for Rule or Flag Default selection, plus validation warnings for empty documents or empty rules. A Variant Store logger emits selected variant names. Passing the same logger to both the evaluator and the Store produces both sets of entries.

The utility does not log context values, Condition operands, fallbacks, flag values, or attributes. No logger means no utility output. Avoid logging raw error causes, which can contain validator details or transport response bodies.

Differences from Powertools for Python

The local rule engine's conformance baseline is Powertools for Python 3.36.0. These differences apply to local evaluation, not AppConfig's evaluator.

Behavior TypeScript Python 3.36.0
Boolean/number equality and membership Strict types; true is not 1 Booleans can equal numbers
Incompatible Action operands Throw ConditionEvaluationError Warn and return a non-match
Array-index Rule names, such as "10" Reject to preserve Rule order Preserve their written order
Non-object rules, such as [], null, or false Reject Falsy values can behave as absent rules
Boolean modulo context or bounds Reject Booleans can act as integers
TIMEZONE Named IANA zones only Can accept dateutil defaults or offset forms
Date-only datetime bound ending in Z Reject during validation Can pass validation before failing to parse during evaluation

Missing-key non-matches, inclusive schedules, midnight rollover, and Python-style truthiness agree with the baseline. The local Store reads the clock once per call so all Conditions and flags agree on the instant; this is a consistency guarantee, not a different time comparison rule.

Testing your code

Using an in-memory Store

Supply a custom Store to test application behavior without AWS calls. Control its value, enabled, and missing-flag results independently of rule evaluation.

Test a batch and its missing-flag fallback
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import { describe, expect, it } from 'vitest';
import { store } from './customStore.js';

describe('Checkout', () => {
  it('returns an in-memory flag and a missing flag fallback', async () => {
    // Prepare
    const flags = new FeatureFlags({ store });

    // Act
    const result = await flags.evaluateMany({
      flags: { checkout_v2: false, banner: 'none' },
    });

    // Assess
    expect(result).toEqual({ checkout_v2: true, banner: 'none' });
  });
});
Use an in-memory Store in application code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {
  FeatureFlags,
  type Store,
  type StoreResult,
} from '@aws-lambda-powertools/feature-flags';

export const store: Store = {
  name: 'in-memory',
  getMany: async (names, _context) => {
    const results: [string, StoreResult][] = [];
    for (const name of names) {
      results.push([
        name,
        name === 'checkout_v2'
          ? { found: true, value: true, enabled: true }
          : { found: false },
      ]);
    }
    return Object.fromEntries(results);
  },
  getAll: async (_context) => ({
    checkout_v2: { found: true, value: true, enabled: true },
  }),
};

const flags = new FeatureFlags({ store });

export const handler = async () =>
  flags.evaluate({ name: 'checkout_v2', default: false });

Testing local rules

Use ruleEngineStore with an inline document to exercise the real rule engine without mocking retrieval.

Test matching and non-matching contexts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import { describe, expect, it } from 'vitest';

describe('Checkout rules', () => {
  it.each([
    { tier: 'premium', expected: true },
    { tier: 'standard', expected: false },
  ])('evaluates the rule for $tier', async ({ tier, expected }) => {
    // Prepare
    const flags = new FeatureFlags({
      store: ruleEngineStore({
        source: async () => ({
          checkout_v2: {
            default: false,
            rules: {
              premium_customers: {
                when_match: true,
                conditions: [
                  { action: 'EQUALS', key: 'tier', value: 'premium' },
                ],
              },
            },
          },
        }),
      }),
    });

    // Act
    const result = await flags.evaluate({
      name: 'checkout_v2',
      context: { tier },
      default: false,
    });

    // Assess
    expect(result).toBe(expected);
  });
});

Injecting a clock

Supply now: () => Date to ruleEngineStore. All schedule Conditions in the Store call share this instant, so tests do not need fake global timers.

Test a schedule endpoint with a fixed clock
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import {
  FeatureFlags,
  ruleEngineStore,
} from '@aws-lambda-powertools/feature-flags';
import { describe, expect, it } from 'vitest';
import document from './scheduleDocument.json' with { type: 'json' };

describe('Happy hour', () => {
  it('includes the end minute in the configured timezone', async () => {
    // Prepare
    const flags = new FeatureFlags({
      store: ruleEngineStore({
        source: async () => document,
        now: () => new Date('2026-06-01T17:00:59Z'), // 19:00 in Rome.
      }),
    });

    // Act
    const result = await flags.evaluate({ name: 'happy_hour', default: false });

    // Assess
    expect(result).toBe(true);
  });
});

Testing AppConfig Agent Stores

Outside Lambda, or with POWERTOOLS_DEV enabled, Agent Stores make no HTTP request. Set POWERTOOLS_APPCONFIG_AGENT_RETURN_VALUE to a JSON string containing the whole profile. A freeform Store expects a Flag Document; a Variant Store expects flag-keyed Agent results, even for a single flag.

Test normalized Variants in local mode
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import profile from './variantProfile.json' with { type: 'json' };

describe('AppConfig Variants', () => {
  beforeEach(() => {
    vi.stubEnv('POWERTOOLS_DEV', 'true');
    vi.stubEnv(
      'POWERTOOLS_APPCONFIG_AGENT_RETURN_VALUE',
      JSON.stringify(profile)
    );
  });
  afterEach(() => {
    vi.unstubAllEnvs();
  });

  it('normalizes a whole local profile without calling the Agent', async () => {
    // Prepare
    const { handler } = await import('./variantStore.js');

    // Act
    const result = await handler();

    // Assess
    expect(result.attributes).toEqual({ theme: 'dark' });
    expect(result.variants.checkout).toEqual({
      enabled: false,
      variant: 'default',
      attributes: {},
    });
    expect(result.enabledFeatures).toEqual(['ui_refresh']);
  });
});
Handler using the Variant Store
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
import {
  appConfigVariantStore,
  disabledVariant,
} from '@aws-lambda-powertools/feature-flags/appconfig-agent';

const flags = new FeatureFlags({
  store: appConfigVariantStore({
    application: 'my-app',
    environment: 'prod',
    name: 'features',
  }),
});

export const handler = async () => {
  const context = { email: 'jane@example.org', opted_in_to_beta: true };
  const ui = await flags.evaluate({
    name: 'ui_refresh',
    context,
    default: disabledVariant(),
  });
  const variants = await flags.evaluateMany({
    flags: { ui_refresh: disabledVariant(), checkout: disabledVariant() },
    context,
  });
  const enabledFeatures = await flags.getEnabledFeatures({ context });

  return {
    enabled: ui.enabled,
    attributes: ui.attributes,
    variants,
    enabledFeatures,
  };
};
Whole-profile Agent response fixture
1
2
3
4
{
  "ui_refresh": { "enabled": true, "_variant": "premium", "theme": "dark" },
  "checkout": { "enabled": false }
}

Local mode validates Variant context but does not evaluate AppConfig's rules against it. Supply the Agent results you want to test. Freeform Stores still evaluate local rules. Without a local profile value, both Agent Stores throw a Parameters ParameterNotFoundError, because the configuration is missing, rather than returning flag fallbacks.