diff --git a/cdk/lib/MetricsStack/cdk-metrics-stack.ts b/cdk/lib/MetricsStack/cdk-metrics-stack.ts index 85bf50f4..46ea013f 100644 --- a/cdk/lib/MetricsStack/cdk-metrics-stack.ts +++ b/cdk/lib/MetricsStack/cdk-metrics-stack.ts @@ -34,6 +34,7 @@ export class MetricsStack extends NestedStack { constructor(scope: Construct, id: string, props: MetricsStackProps) { super(scope, id, props); + const region = Stack.of(this).region; const parentStackName = Stack.of(this.nestedStackParent!).stackName; const nestedStackName = 'Metrics'; @@ -194,7 +195,13 @@ export class MetricsStack extends NestedStack { // Integration with EventBridge new events.Rule(this, `${nestedStackName}-StreamEvents-Rule`, { eventPattern: { - source: ['aws.ivs'] + source: ['aws.ivs'], + region: [region], + detailType: [ + 'IVS Stream State Change', + 'IVS Stream Health Change', + 'IVS Limit Breach' + ] }, targets: [ new eventsTargets.ApiGateway(streamEventsApiGateway, { diff --git a/cdk/streamEventsApi/src/postStreamEvents.ts b/cdk/streamEventsApi/src/postStreamEvents.ts index 33d988c3..c8b77499 100644 --- a/cdk/streamEventsApi/src/postStreamEvents.ts +++ b/cdk/streamEventsApi/src/postStreamEvents.ts @@ -38,6 +38,14 @@ const handler = async ( time: eventTime, resources } = request.body; + + // Ignore "AWS API Call via CloudTrail" events + if (eventType === 'AWS API Call via CloudTrail') { + return; + } + + console.info('Incoming Event', JSON.stringify(request.body)); + let { detail: { stream_id: streamId = '' } } = request.body; @@ -135,12 +143,16 @@ const handler = async ( additionalAttributes.hasErrorEvent = false; additionalAttributes.isOpen = 'true'; } - } else if (eventName === SESSION_ENDED) { + } + + if (eventName === SESSION_ENDED) { additionalAttributes.endTime = eventTime; attributesToRemove.push('isOpen'); } - if (eventType === LIMIT_BREACH_EVENT_TYPE) + + if (eventType === LIMIT_BREACH_EVENT_TYPE) { additionalAttributes.hasErrorEvent = true; + } await updateStreamEvents({ additionalAttributes, @@ -151,9 +163,7 @@ const handler = async ( userSub }); } catch (error) { - console.error(error); - console.error(`Event body: ${JSON.stringify(request.body)}`); - + console.error(error, JSON.stringify(request.body)); reply.statusCode = 500; return reply.send({ __type: UNEXPECTED_EXCEPTION });