Skip to content

Bedrock Settings

Note: This documentation is also available in a rendered format here.

Configures Amazon Bedrock model invocation audit logging to S3 and/or CloudWatch, providing monitoring and compliance capabilities for Bedrock model usage, and optional alarms on model token use. Use this module when you need to track and audit all Bedrock model invocations for compliance, cost monitoring, or operational visibility.


Deployed Resources

This module deploys and integrates the following resources:

  • KMS Encryption Key: Custom KMS key for encrypting Bedrock audit logs
  • S3 Bucket (Optional): S3 bucket for storing Bedrock model invocation audit logs
  • CloudWatch Log Group (Optional): CloudWatch Log Group for real-time monitoring of Bedrock model invocations with configurable retention policies
  • IAM Service Role: Dedicated service role for Bedrock logging operations
  • IAM Managed Policy: Custom policy granting permissions for Bedrock to write audit logs to the configured destinations
  • Custom Resource Lambda: Lambda function that configures Bedrock's global model invocation logging settings through AWS APIs
  • Bucket Policy: Resource-based policy allowing Bedrock service to write audit logs to the S3 bucket
  • KMS Key Policy: Key policy allowing Bedrock, CloudWatch Logs, and S3 services to use the encryption key
  • Token Usage Alarms (Optional): CloudWatch alarms on model input and output token counts, per model and/or account-wide, with SSM parameters for each alarm's name and ARN. See Token usage alarms
  • SNS Topic (Optional): Topic the token usage alarms notify, when the module is asked to create one, with optional email subscriptions, its topic policy, and SSM parameters for its name and ARN

bedrock-settings


  • Bedrock Builder — Deploy AgentCore Harnesses, Knowledge Bases, and Guardrails whose invocations will be captured by the audit logging configured here
  • Bedrock AgentCore Runtime — Deploy custom agent runtimes whose Bedrock model invocations will be captured by audit logging
  • GAIA v2 — Deploy a GenAI application backend whose Bedrock model invocations will be captured by audit logging

Security/Compliance Details

This module is designed in alignment with MDAA security/compliance principles and CDK nag rulesets. Additional review is recommended prior to production deployment, ensuring organization-specific compliance requirements are met.

  • Encryption at Rest:
    • All audit logs encrypted using a customer-managed KMS key
    • KMS key policy restricts access to the account root, Bedrock service, and logging services, plus, with a module-created alarm topic, the CloudWatch alarm service for this module's token alarms
  • Encryption in Transit:
    • All log delivery uses TLS-encrypted connections
  • Least Privilege:
    • Dedicated IAM service role scoped to logging destinations only
    • S3 bucket policy uses condition-based access controls with source account and ARN restrictions
    • Cross-service access uses proper service principals and condition keys
  • Logging & Audit:
    • Supports real-time monitoring via CloudWatch for Bedrock model invocation audit logs
    • Supports long-term storage via S3 for Bedrock model invocation audit logs
    • Configurable log retention policies for compliance requirements
  • Monitoring:
    • Optional token usage alarms notify an existing SNS topic, or a module-created topic encrypted with the module KMS key
    • CloudWatch's publish grant on a module-created topic, and its use of the KMS key, are limited to this module's token alarms

Token usage alarms

tokenUsageAlarms alarms when Bedrock model token use in a period exceeds a threshold:

tokenUsageAlarms:
  notificationTopicArn: 'arn:{{partition}}:sns:{{region}}:{{account}}:ai-platform-alerts'
  models:
    nova-micro:
      modelIds: ['amazon.nova-micro-v1:0', 'us.amazon.nova-micro-v1:0']
      inputTokenThreshold: 5000000
      outputTokenThreshold: 1000000
  accountTotal:
    inputTokenThreshold: 50000000
  periodSeconds: 3600 # optional
  • Account-wide - Bedrock publishes InputTokenCount and OutputTokenCount in the AWS/Bedrock namespace for the whole account, not per agent or application. Every alarm counts every caller of the model IDs it covers in this account and Region, whether or not MDAA deployed them.
  • Model IDs are matched exactly - the ModelId dimension is the model or inference-profile ID exactly as the caller passed it, so amazon.nova-micro-v1:0, us.amazon.nova-micro-v1:0, and a global. profile for the same model are separate series. A models entry sums the IDs it lists, up to 10. Calls made through an ID it doesn't list, such as another inference profile for the same model, are not counted.
  • Account total - accountTotal alarms on the series Bedrock publishes without a dimension, the total across all model IDs.
  • Not counted - inference through the OpenAI-compatible bedrock-mantle endpoint publishes to a separate AWS/BedrockMantle namespace, so these alarms don't count it. Prompt-cache reads and writes are published as separate metrics, CacheReadInputTokenCount and CacheWriteInputTokenCount, which these alarms don't watch.
  • Timing - periodSeconds is a whole number of minutes, because Bedrock publishes token metrics at one-minute resolution. periodSeconds x evaluationPeriods can be at most 1 day for a period under an hour, and at most 7 days otherwise.
  • Notification - an existing topic (notificationTopicArn), or a topic the module creates, encrypted with the module KMS key (createNotificationTopic, with notificationEmails to subscribe addresses).

See the AWS runtime metrics documentation for the metrics and their dimensions.


Configuration

MDAA Config

Add the following snippet to your mdaa.yaml under the modules: section of a domain/env in order to use this module:

bedrock-settings: # Module Name can be customized
  module_path: '@aws-mdaa/bedrock-settings' # Must match module NPM package name
  module_configs:
    - ./bedrock-settings.yaml # Filename/path can be customized

Module Config Samples and Variants

Copy the contents of the relevant sample config below into the ./bedrock-settings.yaml file referenced in the MDAA config snippet above.

Minimal Configuration

Enables audit logging to both CloudWatch and S3 with default settings. Start here when you need basic Bedrock invocation auditing with sensible defaults and plan to tune retention or destinations later.

sample-config-minimal.yaml

# Contents available via above link
# Minimal Bedrock Settings module configuration.
# Enables audit logging to both CloudWatch and S3 with default settings.

# Whether to enable Bedrock audit logging to CloudWatch
enableAuditLoggingToCloudwatch: true
# Whether to enable Bedrock audit logging to S3
enableAuditLoggingToS3: true

Comprehensive Configuration

Configures audit logging for Bedrock model invocations to both S3 (long-term retention) and CloudWatch (real-time monitoring), and alarms on token use per model and account-wide. Use this as a reference when you need full control over log retention, encryption, dual-destination audit configuration, and token usage alerting.

sample-config-comprehensive.yaml

# Contents available via above link
# Sample config for the Bedrock Settings module.
# Configures audit logging for Bedrock model invocations to both
# S3 (long-term retention) and CloudWatch (real-time monitoring),
# and alarms on model token use in the account.

# Enables S3 audit logging for Bedrock model invocations.
# Creates an encrypted S3 bucket for storing invocation logs.
# (default: false)
enableAuditLoggingToS3: true

# Enables CloudWatch audit logging for Bedrock model invocations.
# Creates an encrypted CloudWatch Log Group for real-time
# monitoring and alerting. (default: false)
enableAuditLoggingToCloudwatch: true

# (Optional) Alarms on Bedrock model token use. Token metrics are
# account-wide: they count every caller in the account and Region.
tokenUsageAlarms:
  # Create a topic encrypted with the module KMS key. Alternatively,
  # set notificationTopicArn to an existing topic.
  createNotificationTopic: true
  # (Optional) Email addresses subscribed to the created topic. Each
  # must confirm the SNS subscription before delivery begins.
  notificationEmails:
    - 'ai-platform-ops@example.com'
  # (Optional) Per-model alarms, keyed by a name used in the alarm
  # names.
  models:
    nova-micro:
      # Every model and inference-profile ID callers use for this
      # model (1-10). Calls under an ID not listed are not counted.
      modelIds:
        - 'amazon.nova-micro-v1:0'
        - 'us.amazon.nova-micro-v1:0'
      # (Optional) Alarm when input tokens in one period exceed this
      inputTokenThreshold: 5000000
      # (Optional) Alarm when output tokens in one period exceed this
      outputTokenThreshold: 1000000
  # (Optional) Alarms on the account-wide total across all models
  accountTotal:
    # (Optional) Alarm when input tokens in one period exceed this
    inputTokenThreshold: 50000000
    # (Optional) Alarm when output tokens in one period exceed this
    outputTokenThreshold: 10000000
  # (Optional) Alarm period in seconds. (default: 300)
  periodSeconds: 3600
  # (Optional) Number of periods compared to the threshold.
  # (default: 1)
  evaluationPeriods: 3
  # (Optional) Breaching periods within evaluationPeriods required
  # to alarm. (default: evaluationPeriods)
  datapointsToAlarm: 2

Token Usage Alarms with an Existing Notification Topic

Configures CloudWatch audit logging and an account-wide token usage alarm that notifies an existing SNS topic through tokenUsageAlarms.notificationTopicArn, instead of a topic the module creates. Use this when you already manage a central operations or cost topic. It has its own sample because notificationTopicArn and createNotificationTopic (used in the comprehensive configuration) are mutually exclusive. See Token usage alarms.

sample-config-token-alarms-existing-topic.yaml

# Contents available via above link
# Bedrock Settings with token usage alarms notifying an EXISTING SNS topic.
# Demonstrates tokenUsageAlarms.notificationTopicArn; the comprehensive config shows
# tokenUsageAlarms.createNotificationTopic instead.

# Whether to enable Bedrock audit logging to CloudWatch
enableAuditLoggingToCloudwatch: true
# Whether to enable Bedrock audit logging to S3
enableAuditLoggingToS3: false

# Alarms on Bedrock model token use in this account and Region.
tokenUsageAlarms:
  # Notify an existing SNS topic instead of creating one
  notificationTopicArn: 'arn:{{partition}}:sns:{{region}}:{{account}}:ai-platform-alerts'
  # Alarms on the account-wide total across all models
  accountTotal:
    # Alarm when input tokens in one period exceed this
    inputTokenThreshold: 50000000

Config Schema Docs