Creating and managing Functions
This page walks you through creating, attaching, updating, and deleting Functions using the MediaTailor console. Functions let you customize session behavior and ad requests by running logic at key points during playback.
Setting up a function
Creating a function using the console
-
Open the MediaTailor console at https://console.aws.amazon.com/mediatailor/
. -
In the navigation pane, choose Functions.
-
Choose Create function.
-
For Function ID, enter a unique name for the function (for example,
fetchIdentity). -
For Function type, choose
CUSTOM_OUTPUT,HTTP_REQUEST, orSEQUENTIAL_EXECUTOR. The console displays the configuration fields for the selected type. -
Fill in the type-specific configuration fields. For a description of each function type and its fields, see Function types and composition.
-
Choose Create function.
Attaching a function to a playback configuration
A function does not run until you attach it to a playback configuration through a function mapping (a link between a lifecycle hook and a function). The function mapping specifies which lifecycle hook triggers the function.
-
Open the MediaTailor console.
-
In the navigation pane, choose Configurations.
-
Choose the playback configuration you want to update.
-
In the Function mapping section, choose Edit.
-
For each lifecycle hook, select the function to attach:
-
Session initialization hook — Choose a function to run once at session start.
-
Ad request hook — Choose a function to run before each ADS request.
-
-
Choose Save.
Managing functions
Viewing functions
Navigate to Functions to see all functions in your account. Choose a function name to view its configuration.
Updating an existing function
To update a function, navigate to Functions, choose the function, and modify the configuration. The update replaces the entire function definition.
Tip
Save a copy of your function configuration before making changes. There is no built-in versioning or rollback for functions.
Removing a function
Detaching a function from a playback configuration
Before you delete a function, remove it from all playback configurations that reference it.
-
Open the MediaTailor console.
-
In the navigation pane, choose Configurations.
-
Choose the playback configuration.
-
In the Function mapping section, choose Edit.
-
Remove the function from the lifecycle hook.
-
Choose Save.
Deleting a function
Navigate to Functions, select the function, and choose Delete.
Deletion blocking rules
MediaTailor prevents you from deleting a function that is still in use.
| Condition | Result |
|---|---|
| Function is attached to a playback configuration via function mapping | Delete is blocked. Detach the function first. |
Function is referenced in a
SEQUENTIAL_EXECUTOR |
Delete is blocked. Remove the reference from the parent function first. |
| Function is not referenced anywhere | Delete succeeds. |
Validation rules
MediaTailor validates your function when you create or update it. The following checks are performed:
-
Expression syntax — All expressions must be valid JSONata.
-
Restricted functions — Expressions cannot call restricted JSONata functions. See JSONata expression reference for the full list.
-
Output key prefixes — All output keys must start with a recognized namespace prefix. For the list of accepted prefixes, see Lifecycle hooks.
-
Function references — All function IDs in a
FunctionListmust reference existing functions. -
Circular references — A function cannot reference itself, directly or indirectly.
-
Nesting depth — A
SEQUENTIAL_EXECUTORcan call other functions, but those functions cannot themselves beSEQUENTIAL_EXECUTORs.
For specific values and size limits, see Limits.
API reference
To manage functions programmatically, see the AWS Elemental MediaTailor API Reference.