Skip to content

Instantly share code, notes, and snippets.

@jbesw
Last active July 22, 2022 08:19
Show Gist options
  • Save jbesw/08469b18bc45eed1f4b2c0783d132f5d to your computer and use it in GitHub Desktop.
Save jbesw/08469b18bc45eed1f4b2c0783d132f5d to your computer and use it in GitHub Desktop.
EventBridge Rule for Logging to CloudWatch Logs
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: EventBridge Rule Test
Resources:
CFNLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 3
LogGroupName: '/aws/events/eventbridgeLog'
MyALLRule:
Type: AWS::Events::Rule
Properties:
Description: Collects everything
EventPattern:
account:
- "123412341234"
RoleArn: !GetAtt EBAllRole.Arn
Targets:
- Id: 'CloudwatchLogsTarget'
Arn: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${CFNLogGroup}"
EBAllRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service: "events.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- PolicyName: AllowAllEventsToBeLogged
PolicyDocument:
Version: '2012-10-17'
Statement:
Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
@blinkylights23
Copy link

Hi @jbesw! I'm trying to do this with a Rule with a specific EventBusName, but it doesn't seem to be working (no log streams created, no logs).

Is there something different about how custom buses work that affects log delivery? Is the custom bus the reason you're using an AWS::Logs::ResourcePolicy here instead of this Role-based permission ☝️ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment