/
archive.ts
78 lines (71 loc) · 1.92 KB
/
archive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Construct } from 'constructs';
import { IEventBus } from './event-bus';
import { EventPattern } from './event-pattern';
import { CfnArchive } from './events.generated';
import { renderEventPattern } from './util';
import { Duration, Resource } from '../../core';
/**
* The event archive base properties
*/
export interface BaseArchiveProps {
/**
* The name of the archive.
*
* @default - Automatically generated
*/
readonly archiveName?: string;
/**
* A description for the archive.
*
* @default - none
*/
readonly description?: string;
/**
* An event pattern to use to filter events sent to the archive.
*/
readonly eventPattern: EventPattern;
/**
* The number of days to retain events for. Default value is 0. If set to 0, events are retained indefinitely.
* @default - Infinite
*/
readonly retention?: Duration;
}
/**
* The event archive properties
*/
export interface ArchiveProps extends BaseArchiveProps {
/**
* The event source associated with the archive.
*/
readonly sourceEventBus: IEventBus;
}
/**
* Define an EventBridge Archive
*
* @resource AWS::Events::Archive
*/
export class Archive extends Resource {
/**
* The archive name.
* @attribute
*/
public readonly archiveName: string;
/**
* The ARN of the archive created.
* @attribute
*/
public readonly archiveArn: string;
constructor(scope: Construct, id: string, props: ArchiveProps) {
super(scope, id, { physicalName: props.archiveName });
let archive = new CfnArchive(this, 'Archive', {
sourceArn: props.sourceEventBus.eventBusArn,
description: props.description,
eventPattern: renderEventPattern(props.eventPattern),
retentionDays: props.retention?.toDays({ integral: true }) || 0,
archiveName: this.physicalName,
});
this.archiveArn = archive.attrArn;
this.archiveName = archive.ref;
this.node.defaultChild = archive;
}
}