Security for experiments - Amazon CloudWatch
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Security for experiments

This page describes what CloudWatch does on your behalf when it runs an experiment, which role it uses, where the results are stored, and what deleting an experiment removes. For what experiments are, see Experiments.

Permissions to use experiments

Experiment actions are in the cloudwatch namespace and are named after the operations. Each one except ListExperiments is authorized on the experiment's ARN, arn:aws:cloudwatch:<region>:<account-id>:experiment/<experiment-id>. Runs have no ARN of their own: every run action is authorized on the ARN of its experiment. ListExperiments lists the experiments in your account, so it is authorized on *.

  • cloudwatch:CreateExperiment, cloudwatch:GetExperiment, cloudwatch:UpdateExperiment, and cloudwatch:DeleteExperiment

  • cloudwatch:StartExperimentRun, cloudwatch:GetExperimentRun, cloudwatch:ListExperimentRuns, cloudwatch:PutExperimentRunResults, cloudwatch:CompleteExperimentRun, cloudwatch:StopExperimentRun, and cloudwatch:DeleteExperimentRun

  • cloudwatch:ListExperiments

Only the principal that started a run can put results into it, complete it, or stop it, even if another principal has these actions.

You can tag an experiment when you create it. Use aws:RequestTag/* and aws:TagKeys on CreateExperiment, and aws:ResourceTag/* on the other experiment actions. For more information, see Tag-based access control.

The following identity-based policy lets a principal use experiments in one account and Region, and pass one execution role to them. To set a different role on an experiment, the principal needs iam:PassRole on that role as well. In the following JSON policy, replace <region> with your AWS Region, <YOUR_OWN_ACCOUNT_ID> with your account ID, and <execution-role-name> with your role's name.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ExperimentsApi", "Effect": "Allow", "Action": [ "cloudwatch:CreateExperiment", "cloudwatch:GetExperiment", "cloudwatch:UpdateExperiment", "cloudwatch:DeleteExperiment", "cloudwatch:StartExperimentRun", "cloudwatch:GetExperimentRun", "cloudwatch:ListExperimentRuns", "cloudwatch:PutExperimentRunResults", "cloudwatch:CompleteExperimentRun", "cloudwatch:StopExperimentRun", "cloudwatch:DeleteExperimentRun" ], "Resource": "arn:aws:cloudwatch:<region>:<YOUR_OWN_ACCOUNT_ID>:experiment/*" }, { "Sid": "ListExperiments", "Effect": "Allow", "Action": "cloudwatch:ListExperiments", "Resource": "*" }, { "Sid": "PassTheExecutionRole", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::<YOUR_OWN_ACCOUNT_ID>:role/<execution-role-name>" } ] }

What a hosted run does

In a hosted run, CloudWatch runs the experiment for you. It starts an Amazon Bedrock AgentCore batch evaluation against your agent runtime, follows it until it ends, and writes each case's result to your results log group. To make these calls, CloudWatch assumes the experiment's execution role, an IAM role in the experiment's account. CloudWatch makes these calls as that role, so you limit what a hosted run can reach with the role's permissions policy.

You can get the role in either of these ways:

  • Let CloudWatch Omni create it. When you create your space, or set up Omni in the CloudWatch console, CloudWatch Omni can create the role for the account and Region, named CloudWatchOmniExperimentsRole with a suffix, under the /service-role/ path. Its trust policy and permissions policy are the ones shown in this section. Use it for every experiment in that account and Region.

  • Create it yourself. Create an IAM role with the trust policy in Execution role trust policy and the permissions policy that follows. You can narrow its resources to the datasets, runtimes, and log groups that your experiments use.

  • You name the role when you create the experiment (CreateExperiment), and you can change it with UpdateExperiment while no run is in progress. Every experiment needs one.

  • Each time you set the role, the calling principal needs iam:PassRole on it: on CreateExperiment, and on an UpdateExperiment that names a new role.

  • The role must be in the experiment's account. CloudWatch assumes the role once when you create or update the experiment, so a role that it cannot assume fails the request and nothing is saved.

  • Each role session lasts at most 1 hour. CloudWatch assumes the role again as needed during a run. It sets no session tags and no source identity.

The role's permissions policy must allow the Amazon Bedrock AgentCore batch evaluation actions. It must also allow read access to your agent runtime and the datasets that your runs test, query access to your trace log groups, writes to your results log group, and, for trace stats, CloudWatch telemetry queries.

The following JSON permissions policy is the one CloudWatch Omni attaches to the role that it creates. Replace <region> with your AWS Region and <YOUR_OWN_ACCOUNT_ID> with your account ID.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "StartBatchEvaluation", "Effect": "Allow", "Action": "bedrock-agentcore:StartBatchEvaluation", "Resource": [ "arn:aws:bedrock-agentcore:<region>:<YOUR_OWN_ACCOUNT_ID>:batch-evaluate/*", "arn:aws:bedrock-agentcore:<region>:<YOUR_OWN_ACCOUNT_ID>:dataset/*" ] }, { "Sid": "BatchEvaluations", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetBatchEvaluation", "bedrock-agentcore:StopBatchEvaluation" ], "Resource": "arn:aws:bedrock-agentcore:<region>:<YOUR_OWN_ACCOUNT_ID>:batch-evaluate/*" }, { "Sid": "AnyDatasetAndRuntime", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetDataset", "bedrock-agentcore:ListDatasetExamples", "bedrock-agentcore:InvokeAgentRuntime", "bedrock-agentcore:GetAgentRuntime", "bedrock-agentcore:GetAgentRuntimeEndpoint" ], "Resource": [ "arn:aws:bedrock-agentcore:<region>:<YOUR_OWN_ACCOUNT_ID>:dataset/*", "arn:aws:bedrock-agentcore:<region>:<YOUR_OWN_ACCOUNT_ID>:runtime/*" ] }, { "Sid": "DescribeLogGroups", "Effect": "Allow", "Action": "logs:DescribeLogGroups", "Resource": "*" }, { "Sid": "ResultsLogs", "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:GetLogEvents" ], "Resource": [ "arn:aws:logs:<region>:<YOUR_OWN_ACCOUNT_ID>:log-group:/aws/cloudwatch/evaluations/results/*", "arn:aws:logs:<region>:<YOUR_OWN_ACCOUNT_ID>:log-group:/aws/cloudwatch/experiments/*" ] }, { "Sid": "ReadAgentSpans", "Effect": "Allow", "Action": [ "logs:StartQuery", "logs:GetQueryResults", "logs:GetLogEvents", "logs:FilterLogEvents" ], "Resource": [ "arn:aws:logs:<region>:<YOUR_OWN_ACCOUNT_ID>:log-group:aws/spans", "arn:aws:logs:<region>:<YOUR_OWN_ACCOUNT_ID>:log-group:aws/spans:*", "arn:aws:logs:<region>:<YOUR_OWN_ACCOUNT_ID>:log-group:/aws/bedrock-agentcore/runtimes/*" ] }, { "Sid": "StopAgentSpanQueries", "Effect": "Allow", "Action": "logs:StopQuery", "Resource": "*" }, { "Sid": "TraceStatsTelemetryQueries", "Effect": "Allow", "Action": [ "cloudwatch:StartTelemetryQuerySession", "cloudwatch:ListTelemetryQuerySessions", "cloudwatch:StopTelemetryQuerySession", "cloudwatch:StartTelemetryQuery", "cloudwatch:GetTelemetryQueryResults", "cloudwatch:StopTelemetryQuery" ], "Resource": "*" }, { "Sid": "TraceStatsReadRecords", "Effect": "Allow", "Action": "cloudwatch:GetRecords", "Resource": "arn:aws:cloudwatch:<region>:<YOUR_OWN_ACCOUNT_ID>:dataset/default" } ] }
  • ResultsLogs covers results log groups under /aws/cloudwatch/experiments/ and the /aws/cloudwatch/evaluations/results/ log groups where Amazon Bedrock AgentCore writes its evaluation results. If you name a results log group elsewhere, add it to ResultsLogs.

  • With logs:CreateLogGroup, CloudWatch creates the results log group that you name on the experiment, in the Standard log class with no retention period, when it doesn't exist yet. Without it, create the group yourself before you create the experiment.

  • ReadAgentSpans covers aws/spans and the Amazon Bedrock AgentCore runtime log groups. Add any other log group that holds your agent's spans.

  • StartBatchEvaluation is authorized on the new batch evaluation (batch-evaluate/*) and on each dataset that the run tests. Allowing batch-evaluate/* alone is denied.

  • logs:DescribeLogGroups and logs:StopQuery use * because they don't take a log group resource. CloudWatch calls DescribeLogGroups with the name of your results log group as a prefix, to check that the group exists.

  • CloudWatch calls GetAgentRuntime to check the runtime when you create the experiment, and GetAgentRuntimeEndpoint to read the runtime version when a run starts.

  • TraceStatsTelemetryQueries and TraceStatsReadRecords are used only when trace stats are on for the experiment.

  • A custom evaluator that calls an Amazon Bedrock model needs bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream on that model. One that uses a customer managed key also needs kms:Decrypt and kms:DescribeKey on the key, and the key policy must allow the role. Neither is in the policy that CloudWatch Omni attaches, so add them to the role.

Execution role trust policy

The execution role trusts the CloudWatch service principal cloudwatch.amazonaws.com. CloudWatch passes the experiment's account as aws:SourceAccount and the experiment's ARN as aws:SourceArn. Use both conditions, so that the role can be assumed only for experiments in your own account. Because CloudWatch assumes the role for a new experiment before you know its ID, use the wildcard experiment/* in aws:SourceArn.

The following JSON trust policy applies these conditions. Replace <region> with your AWS Region and <YOUR_OWN_ACCOUNT_ID> with your account ID.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "TrustPolicyStatement", "Effect": "Allow", "Principal": { "Service": "cloudwatch.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "<YOUR_OWN_ACCOUNT_ID>" }, "ArnLike": { "aws:SourceArn": "arn:aws:cloudwatch:<region>:<YOUR_OWN_ACCOUNT_ID>:experiment/*" } } } ] }

Where results are stored

Each run writes one case record per test case to its own log stream, {experimentId}/{runId}, in the results log group that you name on the experiment. The group is in the experiment's account and Region, and must use the Standard log class. If it doesn't exist and the execution role allows logs:CreateLogGroup on it, CloudWatch creates it when you create or update the experiment. Each case record includes your agent's input and output for each turn.

The log group is yours, so you control how these records are protected: their retention, the AWS KMS key that encrypts them, and the group's resource policy. Amazon Bedrock AgentCore also writes its evaluation results to the /aws/cloudwatch/evaluations/results/<service-name> log group in your account.

CloudWatch keeps the experiment and run records it needs to run the experiment, with each case's status and scores but not your agent's inputs or outputs. For how these are encrypted, see Data encryption in CloudWatch Omni.

Deleting experiments and runs

DeleteExperiment deletes the experiment and all of its runs, together with the results and case rows CloudWatch stores for them, and removes the experiment's tags. CloudWatch refuses the operation while a run is running or stopping, so stop the run first. A large experiment can take more than one call. The call then fails with a ConflictException that says the delete is in progress. Repeat the call to continue it. DeleteExperimentRun deletes one run that has ended, in the same way. If that run is the experiment's baseline run, CloudWatch clears the baseline. You can't undo either operation.

Neither operation deletes the case records in your results log group. To remove those, delete the run's log stream, or set a retention period on the log group. For a hosted run, neither operation deletes the Amazon Bedrock AgentCore batch evaluation in your account either. Manage it with Amazon Bedrock AgentCore. For more information, see Managing your experiment data.

Logging experiment operations with AWS CloudTrail

AWS CloudTrail records experiments operations, including the read operations, as management events with the event source cloudwatch.amazonaws.com. Events for operations on an existing experiment, and for a successful CreateExperiment, include the experiment's ARN as the resource.

CloudWatch signs the calls that it makes as your execution role with a session of that role. Examples are starting the Amazon Bedrock AgentCore batch evaluation and writing to your log group. Where the receiving service records such a call in CloudTrail, the event names the execution role session as the caller.