forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.ts
41 lines (35 loc) · 990 Bytes
/
policy.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
import { PolicyDocument } from '@aws-cdk/aws-iam';
import { Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnTopicPolicy } from './sns.generated';
import { ITopic } from './topic-base';
/**
* Properties to associate SNS topics with a policy
*/
export interface TopicPolicyProps {
/**
* The set of topics this policy applies to.
*/
readonly topics: ITopic[];
/**
* IAM policy document to apply to topic(s).
*/
readonly policyDocument: PolicyDocument;
}
/**
* Applies a policy to SNS topics.
*/
export class TopicPolicy extends Resource {
/**
* The IAM policy document for this policy.
*/
public readonly document: PolicyDocument;
constructor(scope: Construct, id: string, props: TopicPolicyProps) {
super(scope, id);
this.document = props.policyDocument;
new CfnTopicPolicy(this, 'Resource', {
policyDocument: props.policyDocument,
topics: props.topics.map(t => t.topicArn),
});
}
}