-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathlog-group-resource-policy.ts
50 lines (47 loc) · 1.41 KB
/
log-group-resource-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
42
43
44
45
46
47
48
49
50
import { Construct } from 'constructs';
import * as iam from '../../aws-iam';
import * as cr from '../../custom-resources';
/**
* Construction properties for LogGroupResourcePolicy
*/
export interface LogGroupResourcePolicyProps {
/**
* The log group resource policy name
*/
readonly policyName: string;
/**
* The policy statements for the log group resource logs
*/
readonly policyStatements: [iam.PolicyStatement];
}
/**
* Creates LogGroup resource policies.
*/
export class LogGroupResourcePolicy extends cr.AwsCustomResource {
constructor(scope: Construct, id: string, props: LogGroupResourcePolicyProps) {
const policyDocument = new iam.PolicyDocument({
statements: props.policyStatements,
});
super(scope, id, {
resourceType: 'Custom::CloudwatchLogResourcePolicy',
onUpdate: {
service: 'CloudWatchLogs',
action: 'putResourcePolicy',
parameters: {
policyName: props.policyName,
policyDocument: JSON.stringify(policyDocument),
},
physicalResourceId: cr.PhysicalResourceId.of(id),
},
onDelete: {
service: 'CloudWatchLogs',
action: 'deleteResourcePolicy',
parameters: {
policyName: props.policyName,
},
ignoreErrorCodesMatching: 'ResourceNotFoundException',
},
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({ resources: ['*'] }),
});
}
}