I am trying to set up a standard architecture for feeding a DynamoDB Stream to an EventBridge event bus using an AWS::Pipes::Pipe in a single AWS account. My goal is to capture DynamoDB item-level changes and log them to a CloudWatch log group via an EventBridge rule.
However, my CloudFormation deployment consistently fails, and I'm encountering a NotAuthorizedForSourceException when I try to manually test the event bus with aws events put-events.
The Goal:
A DynamoDB table with a stream enabled (NEW_AND_OLD_IMAGES).
An AWS::Pipes::Pipe that reads from the DynamoDB stream and sends events to a custom EventBridge event bus.
An AWS::Events::Rule that listens for events on the custom event bus and logs them to a CloudWatch log group.
All resources are in the same AWS account and region.
The Problem:
The CloudFormation stack fails to create, and when I manually test the event bus with the following command:
aws events put-events --entries '[{"Source": "aws.dynamodb.listings", "DetailType": "TestEvent", "Detail": "{\"message\": \"This is a test event\"}", "EventBusName": "myproject-event-bus-myprojectBaseInfrastructure-testenv"}]' --region us-west-2 --profile testenv --no-cli-pager
I receive the following error:
{
"FailedEntryCount": 1,
"Entries": [
{
"ErrorCode": "NotAuthorizedForSourceException",
"ErrorMessage": "Not authorized for the source."
}
]
}
This error suggests that the principal making the put-events call is not authorized to use the aws.dynamodb.listings source.
My infrastructure.yaml (simplified):
Here are the relevant sections of my CloudFormation template:
Resources:
myprojectEventBus:
Type: AWS::Events::EventBus
Properties:
Name: !Sub 'myproject-event-bus-${AWS::StackName}'
myprojectEventBusPolicy:
Type: AWS::Events::EventBusPolicy
Properties:
EventBusName: !GetAtt myprojectEventBus.Name
StatementId: "AllowPipeToPutEvents"
Action: "events:PutEvents"
Principal:
Service: pipes.amazonaws.com
myprojectPipeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: pipes.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: myprojectPipePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'dynamodb:DescribeStream'
- 'dynamodb:GetRecords'
- 'dynamodb:GetShardIterator'
- 'dynamodb:ListStreams'
Resource:
- !GetAtt DynamoDBTable.StreamArn
- Effect: Allow
Action:
- 'events:PutEvents'
Resource: !GetAtt myprojectEventBus.Arn
myprojectListingsDynamoDBToEventBusPipe:
Type: AWS::Pipes::Pipe
Properties:
Name: !Sub 'myproject-listings-pipe-${AWS::StackName}'
RoleArn: !GetAtt myprojectPipeRole.Arn
Source: !GetAtt DynamoDBTable.StreamArn
Target: !GetAtt myprojectEventBus.Arn
TargetParameters:
EventBridgeEventBusParameters:
DetailType: "DynamoDBStreamEvent"
Source: "aws.dynamodb.listings"
myprojectEventBridgeLoggingRule:
Type: AWS::Events::Rule
Properties:
Name: !Sub "myproject-log-events-${AWS::StackName}"
EventBusName: !GetAtt myprojectEventBus.Name
EventPattern:
source:
- "aws.dynamodb.listings"
State: ENABLED
Targets:
- Arn: !GetAtt myprojectEventBusLogGroup.Arn
Id: "myprojectEventBusLogGroupTarget"
What I've Tried:
Custom Source Name: I changed the Source in the Pipe and the EventPattern in the Rule to myproject.dynamodb.listings. This resolved the NotAuthorizedForSourceException when manually testing, but the user has indicated that aws.dynamodb.listings is the correct, standard source for DynamoDB Streams.
EventBusPolicy with Condition: I tried adding a Condition to the EventBusPolicy to explicitly allow the aws.dynamodb.listings source:
Condition:
StringEquals:
events:source: "aws.dynamodb.listings"
This also failed, as events:source is not a valid condition key for EventBusPolicy.
EventBusPolicy with Principal: !Ref "AWS::AccountId": I tried setting the Principal to the current account ID, but this did not resolve the NotAuthorizedForSourceException.
My Questions:
What is the correct way to configure AWS::Events::EventBusPolicy to allow an AWS::Pipes::Pipe in the same account to put events with the source aws.dynamodb.listings?
Is an EventBusPolicy even necessary for this single-account scenario, and if not, what is the correct way to grant the necessary permissions?
Why am I getting NotAuthorizedForSourceException when the myprojectPipeRole has events:PutEvents permission? Does the EventBusPolicy override this?
Any help or clarification on the standard setup for this architecture would be greatly appreciated.
Thank you. It was AI Hallucination that somehow survived multiple rounds of AWS Documentation Injection into the prompt