Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/aws-cdk-lib/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,61 @@ import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-re
import { propertyInjectable } from '../../core/lib/prop-injectable';
import * as cxapi from '../../cx-api';

/**
* Whether EventBridge include detailed event information in the records it generates.
* Detailed data can be useful for troubleshooting and debugging.
* This information includes details of the event itself, as well as target details.
*/
export enum IncludeDetail {
/**
* FULL: Include all details related to event itself and the request EventBridge sends to the target.
* Detailed data can be useful for troubleshooting and debugging.
*/
FULL = 'FULL',
/**
* NONE: Does not include any details.
*/
NONE = 'NONE',
}

/**
* The level of logging detail to include. This applies to all log destinations for the event bus.
*/
export enum Level {
/**
* INFO: EventBridge sends any logs related to errors, as well as major steps performed during event processing
*/
INFO = 'INFO',
/**
* ERROR: EventBridge sends any logs related to errors generated during event processing and target delivery.
*/
ERROR = 'ERROR',
/**
* TRACE: EventBridge sends any logs generated during all steps in the event processing.
*/
TRACE = 'TRACE',
/**
* OFF: EventBridge does not send any logs. This is the default.
*/
OFF = 'OFF',
}

/**
* Interface for Logging Configuration of the Event Bus
*/
export interface LogConfig {
/**
* Whether EventBridge include detailed event information in the records it generates.
* @default no details
*/
readonly includeDetail?: IncludeDetail;
/**
* Logging level
* @default OFF
*/
readonly level?: Level;
}

/**
* Interface which all EventBus based classes MUST implement
*/
Expand Down Expand Up @@ -112,6 +167,11 @@ export interface EventBusProps {
* @default - Use an AWS managed key
*/
readonly kmsKey?: kms.IKey;
/**
* The Logging Configuration of the Èvent Bus.
* @default - no logging
*/
readonly logConfig?: LogConfig;
}

/**
Expand Down Expand Up @@ -405,6 +465,7 @@ export class EventBus extends EventBusBase {
} : undefined,
description: props?.description,
kmsKeyIdentifier: props?.kmsKey?.keyArn,
logConfig: props?.logConfig,
});

this.eventBusArn = this.getResourceArnAttribute(eventBus.attrArn, {
Expand Down
24 changes: 23 additions & 1 deletion packages/aws-cdk-lib/aws-events/test/event-bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import * as sqs from '../../aws-sqs';
import { Aws, CfnResource, Stack, Arn, App, PhysicalName, CfnOutput } from '../../core';
import { EventBus } from '../lib';
import { EventBus, IncludeDetail, Level } from '../lib';

describe('event bus', () => {
test('default event bus', () => {
Expand All @@ -20,6 +20,28 @@ describe('event bus', () => {
});
});

test('default event bus with logConfig', () => {
// GIVEN
const stack = new Stack();

// WHEN
new EventBus(stack, 'Bus', {
logConfig: {
includeDetail: IncludeDetail.FULL,
level: Level.TRACE,
},
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBus', {
Name: 'Bus',
LogConfig: {
IncludeDetail: 'FULL',
Level: 'TRACE',
},
});
});

test('default event bus with empty props object', () => {
// GIVEN
const stack = new Stack();
Expand Down
Loading