-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathsns.ts
49 lines (43 loc) · 1.37 KB
/
sns.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
import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha';
import { IRole } from 'aws-cdk-lib/aws-iam';
import { ITopic } from 'aws-cdk-lib/aws-sns';
/**
* SNS target properties.
*/
export interface SnsTargetParameters {
/**
* The input transformation to apply to the message before sending it to the target.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetparameters.html#cfn-pipes-pipe-pipetargetparameters-inputtemplate
* @default - none
*/
readonly inputTransformation?: IInputTransformation;
}
/**
* A EventBridge Pipes target that sends messages to an SNS topic.
*/
export class SnsTarget implements ITarget {
private topic: ITopic;
private topicParameters?: SnsTargetParameters;
public readonly targetArn: string;
constructor(topic: ITopic, parameters?: SnsTargetParameters) {
this.topic = topic;
this.targetArn = topic.topicArn;
this.topicParameters = parameters;
}
grantPush(grantee: IRole): void {
this.topic.grantPublish(grantee);
}
bind(pipe: IPipe): TargetConfig {
if (!this.topicParameters?.inputTransformation) {
return {
targetParameters: {},
};
}
return {
targetParameters: {
inputTemplate: this.topicParameters.inputTransformation?.bind(pipe).inputTemplate,
},
};
}
}