Home / AI & GenAI

AI & GenAIRunbookIntermediate

Bedrock model invocation logs missing or incomplete: S3 policy, CloudWatch role, KMS and delivery alarms

Invocation logging is on, but records never arrive, stop arriving or lack prompts. Find the broken delivery step, fix permissions and alarm on failures.

Deepak Bhardwaj8 min read

Applies toAmazon Bedrock model invocation logging (bedrock-runtime endpoint), CloudWatch Logs, Amazon S3, AWS KMS, AWS CLI v2

Use this runbook when Bedrock calls succeed but their invocation log records are missing. Failed log delivery doesn't fail the model call, so the application looks healthy while your audit trail has a hole in it.

Work in order: the configuration, then delivery metrics, then the destination that is failing.

Symptom, cause and fix

Symptom Likely cause Fix
No records at all in one Region Logging is not configured in that Region Enable it per Region (step 1)
Records stopped after a Terraform or CLI change A put call replaced the whole configuration Restore the full configuration (step 3)
CloudWatch failure metric rises Role trust, role permissions or log group Step 4
S3 failure metric rises Bucket policy, ACLs or KMS key policy Step 5
Record exists but the prompt is a reference or absent Body over 100 KB, or the data type is switched off Step 6
Some apps logged, others not Different Region, account or endpoint Step 2

Set the variables

export REGION=us-east-1
export ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
export LOG_GROUP=/bedrock/invocations
export BUCKET=my-bedrock-logs
export PREFIX=bedrock
export ROLE=BedrockInvocationLogging

1. Read the current configuration

aws bedrock get-model-invocation-logging-configuration --region $REGION

An empty response means logging is off. It is off by default, and you need it in every Region that your applications call. Check them all:

for r in us-east-1 us-west-2 eu-west-1 eu-central-1; do
  echo "== $r"
  aws bedrock get-model-invocation-logging-configuration --region $r \
    --query 'loggingConfig.{cw:cloudWatchConfig.logGroupName,s3:s3Config.bucketName,text:textDataDeliveryEnabled}' \
    --output json
done

If it was on yesterday, find who changed it:

for e in PutModelInvocationLoggingConfiguration DeleteModelInvocationLoggingConfiguration; do
  aws cloudtrail lookup-events --region $REGION \
    --lookup-attributes AttributeKey=EventName,AttributeValue=$e \
    --query 'Events[].{time:EventTime,user:Username,event:EventName}' --output table
done

2. Confirm the call should be logged

Invocation logging covers Converse, ConverseStream, InvokeModel and InvokeModelWithResponseStream. It also covers the OpenAI-compatible Responses and Chat Completions APIs when they are called on the bedrock-runtime endpoint.

At the time of writing, AWS documents that calls through other endpoints, including bedrock-mantle, are not captured. Check the base URL of any app that uses the OpenAI SDK before you spend time on IAM.

Send one known call, so that you have something to look for:

aws bedrock-runtime converse --region $REGION \
  --model-id <MODEL_OR_INFERENCE_PROFILE_ID> \
  --messages '[{"role":"user","content":[{"text":"logging probe 001"}]}]' \
  --inference-config maxTokens=20

aws logs filter-log-events --region $REGION \
  --log-group-name $LOG_GROUP \
  --filter-pattern '"logging probe 001"' \
  --query 'events[].message' --output text

Allow a few minutes for delivery. S3 objects are written in batches, so they can lag behind CloudWatch.

Next, see which destination is failing. Bedrock publishes delivery counters in AWS/Bedrock. List them first, because the dimension values matter in later queries:

aws cloudwatch list-metrics --region $REGION --namespace AWS/Bedrock \
  --query "Metrics[?starts_with(MetricName,'ModelInvocation')].[MetricName,Dimensions]" \
  --output json
Metric ending in DeliveryFailure Look at
ModelInvocationLogsCloudWatchDeliveryFailure Step 4
ModelInvocationLogsS3DeliveryFailure Step 5
ModelInvocationLargeDataS3DeliveryFailure Steps 5 and 6

3. Restore the full configuration

Warning

Save the existing configuration before you run put. Send the complete set of destinations and data types each time rather than only the field you want to change.

aws bedrock get-model-invocation-logging-configuration \
  --region $REGION > logging-before.json

cat > logging.json <<EOF
{
  "cloudWatchConfig": {
    "logGroupName": "$LOG_GROUP",
    "roleArn": "arn:aws:iam::$ACCOUNT:role/$ROLE",
    "largeDataDeliveryS3Config": {
      "bucketName": "$BUCKET",
      "keyPrefix": "$PREFIX"
    }
  },
  "s3Config": { "bucketName": "$BUCKET", "keyPrefix": "$PREFIX" },
  "textDataDeliveryEnabled": true,
  "imageDataDeliveryEnabled": true,
  "embeddingDataDeliveryEnabled": false
}
EOF

aws bedrock put-model-invocation-logging-configuration \
  --region $REGION --logging-config file://logging.json

The role, log group and bucket must exist first. Destinations must be in the same account and Region as the logging configuration.

Caution

These logs can hold full prompts and answers, including personal data and secrets that users paste. Restrict read access, encrypt them and set retention before turning on text delivery in production.

4. Fix CloudWatch Logs delivery

Check that the log group exists and that the role has the right trust and permissions:

aws logs describe-log-groups --region $REGION --log-group-name-prefix $LOG_GROUP \
  --query 'logGroups[].{name:logGroupName,days:retentionInDays,kms:kmsKeyId}'
aws iam get-role --role-name $ROLE --query 'Role.AssumeRolePolicyDocument'
aws iam list-role-policies --role-name $ROLE
aws iam list-attached-role-policies --role-name $ROLE

Create the log group if it is gone. Set retention at the same time:

aws logs create-log-group --region $REGION --log-group-name $LOG_GROUP
aws logs put-retention-policy --region $REGION \
  --log-group-name $LOG_GROUP --retention-in-days 30

Apply a trust policy for the Bedrock service principal, limited to your account:

cat > trust.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "bedrock.amazonaws.com" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": { "aws:SourceAccount": "$ACCOUNT" },
      "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:$REGION:$ACCOUNT:*" }
    }
  }]
}
EOF

cat > perms.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
    "Resource": "arn:aws:logs:$REGION:$ACCOUNT:log-group:$LOG_GROUP:log-stream:aws/bedrock/modelinvocations"
  }]
}
EOF

aws iam update-assume-role-policy --role-name $ROLE --policy-document file://trust.json
aws iam put-role-policy --role-name $ROLE \
  --policy-name BedrockLogWrite --policy-document file://perms.json

Common mistakes are a SourceArn with the wrong Region when one role is copied to a second Region, and a log group renamed in the configuration but not in the policy. If one role serves several Regions, list each Region's ARN in both policies; the commands above would replace what is there.

5. Fix S3 delivery

Check ownership first. ACLs must be disabled for the bucket policy to take effect, which means BucketOwnerEnforced:

aws s3api get-bucket-location --bucket $BUCKET
aws s3api get-bucket-ownership-controls --bucket $BUCKET
aws s3api get-bucket-encryption --bucket $BUCKET
aws s3api get-bucket-policy --bucket $BUCKET --query Policy --output text > policy-before.json

The policy needs this statement:

{
  "Sid": "AmazonBedrockLogsWrite",
  "Effect": "Allow",
  "Principal": { "Service": "bedrock.amazonaws.com" },
  "Action": "s3:PutObject",
  "Resource": "arn:aws:s3:::my-bedrock-logs/bedrock/AWSLogs/111122223333/BedrockModelInvocationLogs/*",
  "Condition": {
    "StringEquals": { "aws:SourceAccount": "111122223333" },
    "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:*" }
  }
}

Warning

put-bucket-policy replaces the whole policy. Merge the statement into policy-before.json and save that as policy.json.

aws s3api put-bucket-policy --bucket $BUCKET --policy file://policy.json

Also look for explicit Deny statements. A rule that requires a particular encryption header or VPC endpoint can reject the service's write even though the Allow is correct.

Buckets encrypted with a customer managed key

The KMS key policy must let Bedrock generate data keys. Add this to the existing key policy without removing the administrator statements:

{
  "Sid": "AllowBedrockLogDelivery",
  "Effect": "Allow",
  "Principal": { "Service": "bedrock.amazonaws.com" },
  "Action": "kms:GenerateDataKey",
  "Resource": "*",
  "Condition": {
    "StringEquals": { "aws:SourceAccount": "111122223333" },
    "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:*" }
  }
}

A KMS-encrypted log group is a separate case: its key policy must allow the CloudWatch Logs service principal for the Region.

6. Explain missing prompt content

Records with token counts but no prompt text usually have one of two causes:

  • Data type off. Check textDataDeliveryEnabled and the image and embedding flags in step 1.
  • Body too large. JSON bodies up to 100 KB are inlined. Larger bodies and binary data go to separate S3 objects, and the record holds a reference. Set largeDataDeliveryS3Config if CloudWatch is your main destination, and give log readers access to that prefix.

Confirm what is arriving with a Logs Insights query:

fields @timestamp, modelId, operation, identity.arn, input.inputTokenCount, output.outputTokenCount
| sort @timestamp desc
| limit 20

7. Verify

Repeat the probe from step 2 with a new marker string, then check S3 for new objects:

aws s3 ls s3://$BUCKET/$PREFIX/AWSLogs/$ACCOUNT/BedrockModelInvocationLogs/ --recursive | tail -5

After a fix, don't count on missed records being backfilled. Note the gap in the incident record. Invocation metrics in AWS/Bedrock still show how many calls happened in that window.

Prevent it next time

  • Alarm on each delivery failure metric. Take the dimensions from list-metrics and paste them in:
aws cloudwatch put-metric-alarm --region $REGION \
  --alarm-name bedrock-log-s3-delivery-failure \
  --namespace AWS/Bedrock --metric-name ModelInvocationLogsS3DeliveryFailure \
  --dimensions Name=<NAME>,Value=<VALUE> \
  --statistic Sum --period 300 --evaluation-periods 1 --threshold 0 \
  --comparison-operator GreaterThanThreshold --treat-missing-data notBreaching \
  --alarm-actions <SNS_TOPIC_ARN>
  • Create an EventBridge rule or CloudTrail alarm for the put and delete logging configuration events.
  • Manage the configuration, bucket policy, key policy and role in one infrastructure-as-code module, deployed to each Region you use.
  • Run the probe daily and alert if the marker isn't found.
  • Allow bedrock:PutModelInvocationLoggingConfiguration and the delete action for platform roles only.
  • Block or review use of endpoints that invocation logging doesn't cover.