Skip to content

Commit a5a8855

Browse files
authored
fix(opensearch): always create CloudWatch Logs resource policy when logging is enabled (#28707)
This PR adds an option to suppress the creation of logs resource policy when logging is enabled. ### Description Currently, a CloudWatch Logs resource policy is created by default when the Domain logging is enabled. However, since only ten resource policies can be created per region, deploying multiple Domains may cause errors. The `tryRemoveChild` method can be used as a workaround to delete custom resources, but a better user experience is desirable. ```ts const domain = new opensearch.Domain(this, 'Domain', domainProps); const domainResource = domain.node.defaultChild as opensearch.CfnDomain; domainResource.addOverride('DependsOn', undefined); // remove dependency on the custom resource domain.node.children .filter(child => child instanceof AwsCustomResource) .forEach(value => domain.node.tryRemoveChild(value.node.id)); ``` So, I add an option to suppress the creation of resource policies. This option allows users to reuse a broader resource policy and successfully deploy several domains. https://docs.aws.amazon.com/opensearch-service/latest/developerguide/createdomain-configure-slow-logs.html#:~:text=Resource%22%3A%20%22cw_log_group_arn%3A*%22%7D%5D%7D%27-,Important,-CloudWatch%20Logs%20supports Closes #23637 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2952408 commit a5a8855

14 files changed

+854
-1
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/cdkinteg-logs-resource-policy.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"Resources": {
3+
"AppLogsGroupC90FBC0A": {
4+
"Type": "AWS::Logs::LogGroup",
5+
"Properties": {
6+
"RetentionInDays": 731
7+
},
8+
"UpdateReplacePolicy": "Delete",
9+
"DeletionPolicy": "Delete"
10+
},
11+
"ResourcePolicyD790E185": {
12+
"Type": "AWS::Logs::ResourcePolicy",
13+
"Properties": {
14+
"PolicyDocument": {
15+
"Fn::Join": [
16+
"",
17+
[
18+
"{\"Statement\":[{\"Action\":[\"logs:CreateLogStream\",\"logs:PutLogEvents\"],\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"es.amazonaws.com\"},\"Resource\":\"",
19+
{
20+
"Fn::GetAtt": [
21+
"AppLogsGroupC90FBC0A",
22+
"Arn"
23+
]
24+
},
25+
"\"}],\"Version\":\"2012-10-17\"}"
26+
]
27+
]
28+
},
29+
"PolicyName": "cdkinteglogsresourcepolicyResourcePolicyB41E8C17"
30+
}
31+
}
32+
},
33+
"Outputs": {
34+
"ExportsOutputFnGetAttAppLogsGroupC90FBC0AArn7BBE8767": {
35+
"Value": {
36+
"Fn::GetAtt": [
37+
"AppLogsGroupC90FBC0A",
38+
"Arn"
39+
]
40+
},
41+
"Export": {
42+
"Name": "cdkinteg-logs-resource-policy:ExportsOutputFnGetAttAppLogsGroupC90FBC0AArn7BBE8767"
43+
}
44+
}
45+
},
46+
"Parameters": {
47+
"BootstrapVersion": {
48+
"Type": "AWS::SSM::Parameter::Value<String>",
49+
"Default": "/cdk-bootstrap/hnb659fds/version",
50+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
51+
}
52+
},
53+
"Rules": {
54+
"CheckBootstrapVersion": {
55+
"Assertions": [
56+
{
57+
"Assert": {
58+
"Fn::Not": [
59+
{
60+
"Fn::Contains": [
61+
[
62+
"1",
63+
"2",
64+
"3",
65+
"4",
66+
"5"
67+
],
68+
{
69+
"Ref": "BootstrapVersion"
70+
}
71+
]
72+
}
73+
]
74+
},
75+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
76+
}
77+
]
78+
}
79+
}
80+
}

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/cdkinteg-opensearch-without-logs-resource-policy.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"Resources": {
3+
"Domain66AC69E0": {
4+
"Type": "AWS::OpenSearchService::Domain",
5+
"Properties": {
6+
"ClusterConfig": {
7+
"DedicatedMasterEnabled": false,
8+
"InstanceCount": 1,
9+
"InstanceType": "r5.large.search",
10+
"MultiAZWithStandbyEnabled": false,
11+
"ZoneAwarenessEnabled": false
12+
},
13+
"DomainEndpointOptions": {
14+
"EnforceHTTPS": false,
15+
"TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07"
16+
},
17+
"EBSOptions": {
18+
"EBSEnabled": true,
19+
"VolumeSize": 10,
20+
"VolumeType": "gp2"
21+
},
22+
"EncryptionAtRestOptions": {
23+
"Enabled": false
24+
},
25+
"EngineVersion": "OpenSearch_2.11",
26+
"LogPublishingOptions": {
27+
"ES_APPLICATION_LOGS": {
28+
"CloudWatchLogsLogGroupArn": {
29+
"Fn::ImportValue": "cdkinteg-logs-resource-policy:ExportsOutputFnGetAttAppLogsGroupC90FBC0AArn7BBE8767"
30+
},
31+
"Enabled": true
32+
}
33+
},
34+
"NodeToNodeEncryptionOptions": {
35+
"Enabled": false
36+
}
37+
},
38+
"UpdateReplacePolicy": "Delete",
39+
"DeletionPolicy": "Delete"
40+
}
41+
},
42+
"Parameters": {
43+
"BootstrapVersion": {
44+
"Type": "AWS::SSM::Parameter::Value<String>",
45+
"Default": "/cdk-bootstrap/hnb659fds/version",
46+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
47+
}
48+
},
49+
"Rules": {
50+
"CheckBootstrapVersion": {
51+
"Assertions": [
52+
{
53+
"Assert": {
54+
"Fn::Not": [
55+
{
56+
"Fn::Contains": [
57+
[
58+
"1",
59+
"2",
60+
"3",
61+
"4",
62+
"5"
63+
],
64+
{
65+
"Ref": "BootstrapVersion"
66+
}
67+
]
68+
}
69+
]
70+
},
71+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
72+
}
73+
]
74+
}
75+
}
76+
}

packages/@aws-cdk-testing/framework-integ/test/aws-opensearchservice/test/integ.opensearch.without-logs-resource-policy.js.snapshot/integ.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)