Skip to content

Commit ebba9e3

Browse files
authored
fix(opensearch): log group policies ignore incorrect error code on delete (#22364)
Updates ignore error code to reflect actual error code and gracefully handle the case when a log group policy is being deleted but already does not exist, because the cluster was shut down previously. Observed behaviour: ``` ResourceNotFoundException: Policy with name [ESLogPolicyc83ee46895a093e947614fc60b86c1a65d36a02321] does not exist. at Request.extractError (/tmp/node_modules/aws-sdk/lib/protocol/json.js:52:27) at Request.callListeners (/tmp/node_modules/aws-sdk/lib/sequential_executor.js:106:20) at Request.emit (/tmp/node_modules/aws-sdk/lib/sequential_executor.js:78:10) at Request.emit (/tmp/node_modules/aws-sdk/lib/request.js:686:14) at Request.transition (/tmp/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/tmp/node_modules/aws-sdk/lib/state_machine.js:14:12) at /tmp/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/tmp/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/tmp/node_modules/aws-sdk/lib/request.js:688:12) at Request.callListeners (/tmp/node_modules/aws-sdk/lib/sequential_executor.js:116:18) { code: 'ResourceNotFoundException', time: 2022-10-04T16:28:57.966Z, requestId: '719a967b-bfea-435a-9aeb-ca8b67888e47', statusCode: 400, retryable: false, retryDelay: 38.982884472906434 } Responding { "Status": "FAILED", "Reason": "Policy with name [ESLogPolicyc83ee46895a093e947614fc60b86c1a65d36a02321] does not exist.", "PhysicalResourceId": "2022/10/04/[$LATEST]b282f3f11b1142c0afe77f0d62523288", "StackId": "arn:aws:cloudformation:eu-central-1:XXXXX:stack/XXXXX/06651720-40b5-11ed-887d-0a422088f326", "RequestId": "90891990-91c1-43bf-82e3-0d98832fc82c", "LogicalResourceId": "OpenSearchDomainESLogGroupPolicyc83ee46895a093e947614fc60b86c1a65d36a02321E1EA3F89", "NoEcho": false, "Data": {} } ``` ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0837c1a commit ebba9e3

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

packages/@aws-cdk/aws-elasticsearch/lib/log-group-resource-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class LogGroupResourcePolicy extends cr.AwsCustomResource {
4242
parameters: {
4343
policyName: props.policyName,
4444
},
45-
ignoreErrorCodesMatching: '400',
45+
ignoreErrorCodesMatching: 'ResourceNotFoundException',
4646
},
4747
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({ resources: ['*'] }),
4848
});

packages/@aws-cdk/aws-elasticsearch/test/elasticsearch.custom-kms-key.integ.snapshot/cdk-integ-elasticsearch-custom-kms-key.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
]
105105
]
106106
},
107-
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc82ca7bfe2f2589b859ebab89e88da2efd284adfad\"},\"ignoreErrorCodesMatching\":\"400\"}",
107+
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc82ca7bfe2f2589b859ebab89e88da2efd284adfad\"},\"ignoreErrorCodesMatching\":\"ResourceNotFoundException\"}",
108108
"InstallLatestAwsSdk": true
109109
},
110110
"DependsOn": [

packages/@aws-cdk/aws-elasticsearch/test/elasticsearch.integ.snapshot/cdk-integ-elasticsearch.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
]
7070
]
7171
},
72-
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc8858d5dba055f677469d76cb6ad538fd732ba69a6\"},\"ignoreErrorCodesMatching\":\"400\"}",
72+
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc8858d5dba055f677469d76cb6ad538fd732ba69a6\"},\"ignoreErrorCodesMatching\":\"ResourceNotFoundException\"}",
7373
"InstallLatestAwsSdk": true
7474
},
7575
"DependsOn": [
@@ -377,7 +377,7 @@
377377
]
378378
]
379379
},
380-
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc8405238e455eeabd840cf6933e1814efc51d2de71\"},\"ignoreErrorCodesMatching\":\"400\"}",
380+
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc8405238e455eeabd840cf6933e1814efc51d2de71\"},\"ignoreErrorCodesMatching\":\"ResourceNotFoundException\"}",
381381
"InstallLatestAwsSdk": true
382382
},
383383
"DependsOn": [

packages/@aws-cdk/aws-elasticsearch/test/log-group-resource-policy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test('minimal example renders correctly', () => {
5959
parameters: {
6060
policyName: 'TestPolicy',
6161
},
62-
ignoreErrorCodesMatching: '400',
62+
ignoreErrorCodesMatching: 'ResourceNotFoundException',
6363
}),
6464
});
6565
});

packages/@aws-cdk/aws-opensearchservice/lib/log-group-resource-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class LogGroupResourcePolicy extends cr.AwsCustomResource {
4242
parameters: {
4343
policyName: props.policyName,
4444
},
45-
ignoreErrorCodesMatching: '400',
45+
ignoreErrorCodesMatching: 'ResourceNotFoundException',
4646
},
4747
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({ resources: ['*'] }),
4848
});

packages/@aws-cdk/aws-opensearchservice/test/log-group-resource-policy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test('minimal example renders correctly', () => {
5959
parameters: {
6060
policyName: 'TestPolicy',
6161
},
62-
ignoreErrorCodesMatching: '400',
62+
ignoreErrorCodesMatching: 'ResourceNotFoundException',
6363
}),
6464
});
6565
});

packages/@aws-cdk/aws-opensearchservice/test/opensearch.integ.snapshot/cdk-integ-opensearch.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
]
7070
]
7171
},
72-
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc881416c4fcb1ec2b4bf7f47a5cde4097f01ec50fc\"},\"ignoreErrorCodesMatching\":\"400\"}",
72+
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc881416c4fcb1ec2b4bf7f47a5cde4097f01ec50fc\"},\"ignoreErrorCodesMatching\":\"ResourceNotFoundException\"}",
7373
"InstallLatestAwsSdk": true
7474
},
7575
"DependsOn": [
@@ -374,7 +374,7 @@
374374
]
375375
]
376376
},
377-
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc80140a7754e9c0dd4e81167ef19e15da5b55dca02\"},\"ignoreErrorCodesMatching\":\"400\"}",
377+
"Delete": "{\"service\":\"CloudWatchLogs\",\"action\":\"deleteResourcePolicy\",\"parameters\":{\"policyName\":\"ESLogPolicyc80140a7754e9c0dd4e81167ef19e15da5b55dca02\"},\"ignoreErrorCodesMatching\":\"ResourceNotFoundException\"}",
378378
"InstallLatestAwsSdk": true
379379
},
380380
"DependsOn": [

0 commit comments

Comments
 (0)