> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plerion.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Log AgentCore Gateway data events in CloudTrail

> Turn on CloudTrail data events for your Amazon Bedrock AgentCore gateways on a trail you already have

With **[CloudTrail data events](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/enabling-cloudtrail-data-event-logging.html)** turned on for your Amazon Bedrock AgentCore gateways, your trail records who called which tool and whether the gateway allowed it. A gateway is the endpoint that AgentCore agents call their tools through. CloudTrail does not log these events by default, and Plerion does not turn them on for you.

***

## What to turn on

Add one data event selector to a trail that logs the gateway's account. This can be an organization trail, which only its management account can change. The selector has `eventCategory` set to `Data` and `resources.type` set to `AWS::BedrockAgentCore::Gateway`.

A trail logs data events only in the regions it covers. Use a multi-region trail, or one trail in each region that has a gateway.

AWS charges \$0.10 for every 100,000 data events the trail delivers. A gateway produces one event for each request it receives, which includes requests that list tools as well as tool calls. See [AWS CloudTrail pricing](https://aws.amazon.com/cloudtrail/pricing/).

***

## Add the selector to a trail

> [tab] AWS console
>
> 1. In the CloudTrail console, choose **Trails** and open the trail.
> 2. In **Data events**, choose **Edit**.
> 3. If the trail logs no data events yet, select the **Data events** check box. If it does, choose **Add data event type**.
> 4. For **Resource type**, choose **Bedrock-AgentCore Gateway**.
> 5. For the log selector template, choose **Log all events**.
> 6. Choose **Save changes**.

> [tab] AWS CLI
>
> > [!WARNING]
> >
> > `put-event-selectors` replaces every selector on the trail. Send the selectors the trail already has together with the new one. The command in the AWS AgentCore guide sends the gateway selector alone. If you run it on a trail you already use, the trail stops logging management events and any other data events.
>
> Both commands must run in the trail's home region, which is `HomeRegion` in the output of `aws cloudtrail describe-trails`.
>
> 1. Read the selectors the trail has now:
>
>    ```bash theme={"system"}
>    aws cloudtrail get-event-selectors --trail-name <trail-name> --region <home-region>
>    ```
>
> 2. Build `selectors.json` from the output:
>
>    * If the output has `AdvancedEventSelectors`, save that array to `selectors.json` and add the gateway selector to it.
>    * If it has `EventSelectors`, the trail uses basic event selectors. They cannot log gateway events, and a trail cannot have both kinds, so rewrite each one as an advanced selector that logs the same events. The AWS guide to [logging data events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html) has examples.
>
>    For a trail that logs all management events and nothing else, the file is:
>
>    ```json theme={"system"}
>    [
>      {
>        "Name": "Management events",
>        "FieldSelectors": [
>          { "Field": "eventCategory", "Equals": ["Management"] }
>        ]
>      },
>      {
>        "Name": "AgentCore Gateway data events",
>        "FieldSelectors": [
>          { "Field": "eventCategory", "Equals": ["Data"] },
>          { "Field": "resources.type", "Equals": ["AWS::BedrockAgentCore::Gateway"] }
>        ]
>      }
>    ]
>    ```
>
> 3. Write the selectors back:
>
>    ```bash theme={"system"}
>    aws cloudtrail put-event-selectors --trail-name <trail-name> --region <home-region> \
>      --advanced-event-selectors file://selectors.json
>    ```

> [tab] CloudFormation
>
> Add the gateway selector to the `AdvancedEventSelectors` property of the `AWS::CloudTrail::Trail` resource.
>
> A trail with no selectors in its template logs all management events. Once the template sets `AdvancedEventSelectors`, the trail logs only what they select, so add the management events selector as well:
>
> ```yaml theme={"system"}
> Properties:
>   AdvancedEventSelectors:
>     - Name: Management events
>       FieldSelectors:
>         - Field: eventCategory
>           Equals:
>             - Management
>     - Name: AgentCore Gateway data events
>       FieldSelectors:
>         - Field: eventCategory
>           Equals:
>             - Data
>         - Field: resources.type
>           Equals:
>             - AWS::BedrockAgentCore::Gateway
> ```
>
> If the resource has `EventSelectors`, replace them with advanced selectors that log the same events. A trail cannot have both kinds.

***

## Check that it worked

After the next scan, **\[PLERION-AWS-1239]** "CloudTrail does not log data events for AgentCore gateways" passes for each gateway the trail covers.

***

## What Plerion reads

Once the trail logs these events, Plerion receives them through the [Cloud Detection and Response (CDR) integration](https://docs.plerion.com/guides/integrations/aws/additional-aws-configurations/cdr-integration.md), which forwards events from the regions its stack is deployed in. Deploy it in each region that has a gateway. From each event it reads:

* The IAM role and session that made the request, with the source IP address and user agent
* The tool that was called, and on which gateway
* Whether the call succeeded, or the error it returned. A call the gateway's policy denies is logged with HTTP status 200 and the JSON-RPC error code `-32002`.

Plerion shows each tool call in the gateway's Event history, with the tool name and whether the gateway allowed it.

Plerion does not receive the arguments sent to a tool or the result it returned. AWS replaces both with `REDACTED` in the event.

Plerion reads the caller for gateways that use IAM authorization. For a gateway that authorizes its callers with a JSON Web Token (JWT), AWS documents that the event carries claims from the token in place of an IAM identity.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.