-
Notifications
You must be signed in to change notification settings - Fork 0
/
osml_topic.ts
56 lines (51 loc) · 1.47 KB
/
osml_topic.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
/*
* Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
*/
import { Key } from "aws-cdk-lib/aws-kms";
import { Topic } from "aws-cdk-lib/aws-sns";
import { Construct } from "constructs";
/**
* Represents the properties for an OSML (OpenStreetMap Location) topic.
* @interface
*/
export interface OSMLTopicProps {
/**
* The name to give the topic.
* @type {string}
*/
topicName: string;
}
/**
* Represents an OSML (Open Source Messaging Library) Topic.
*
* This class provides an abstraction for creating and managing topics for secure messaging
* using AWS Key Management Service (KMS) encryption.
*
* @class
*/
export class OSMLTopic extends Construct {
public key: Key;
public topic: Topic;
/**
* Creates an OSML Topic.
*
* @constructor
* @param {Construct} scope - The scope/stack in which to define this construct.
* @param {string} id - The id of this construct within the current scope.
* @param {OSMLTopicProps} props - The properties of this construct.
* @returns OSMLTopic - The OSMLTopic construct.
*/
constructor(scope: Construct, id: string, props: OSMLTopicProps) {
super(scope, id);
// Create a KMS key for topic encryption
this.key = new Key(this, `${props.topicName}Key`, {
enableKeyRotation: true,
alias: `${props.topicName}Key`
});
// Build the topic and add the key to it
this.topic = new Topic(this, id, {
topicName: props.topicName,
masterKey: this.key
});
}
}