Skip to content

Commit 9ed062a

Browse files
committed
feat: destroy deletes tagged OpenSearch domain and AMP workspace
If the domain and AMP workspace were created by the CLI (tagged with observability-stack), destroy now deletes them too. Reused resources without the tag are left untouched. Signed-off-by: Kyle Hounslow <kylhouns@amazon.com>
1 parent 305baf2 commit 9ed062a

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

aws/cli-installer/src/destroy.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Deletes in reverse dependency order: EC2 → Application → DQS → OSIS → IAM → (preserves AOS/AMP).
44
*/
55
import { OSISClient, DeletePipelineCommand, GetPipelineCommand } from '@aws-sdk/client-osis';
6-
import { OpenSearchClient, ListApplicationsCommand, DeleteApplicationCommand, DeleteDirectQueryDataSourceCommand, GetApplicationCommand, DescribeDomainCommand } from '@aws-sdk/client-opensearch';
6+
import { OpenSearchClient, ListApplicationsCommand, DeleteApplicationCommand, DeleteDirectQueryDataSourceCommand, GetApplicationCommand, DescribeDomainCommand, DeleteDomainCommand } from '@aws-sdk/client-opensearch';
77
import { IAMClient, DeleteRolePolicyCommand, DeleteRoleCommand, ListRolePoliciesCommand, ListAttachedRolePoliciesCommand, DetachRolePolicyCommand } from '@aws-sdk/client-iam';
88
import { printStep, printSuccess, printWarning, printInfo, createSpinner } from './ui.mjs';
99
import { teardownDemoInstance } from './ec2-demo.mjs';
@@ -150,7 +150,34 @@ export async function destroy(cfg) {
150150
if (e.name !== 'ResourceNotFoundException') printWarning(`Secret cleanup: ${e.message}`);
151151
}
152152

153+
// 7. OpenSearch domain (if tagged with this stack)
154+
try {
155+
const { ResourceGroupsTaggingAPIClient, GetResourcesCommand } = await import('@aws-sdk/client-resource-groups-tagging-api');
156+
const tagging = new ResourceGroupsTaggingAPIClient({ region });
157+
const { ResourceTagMappingList } = await tagging.send(new GetResourcesCommand({
158+
TagFilters: [{ Key: 'observability-stack', Values: [pipelineName] }],
159+
ResourceTypeFilters: ['es:domain'],
160+
}));
161+
for (const r of ResourceTagMappingList || []) {
162+
const domainName = r.ResourceARN.split('/').pop();
163+
await os.send(new DeleteDomainCommand({ DomainName: domainName }));
164+
printSuccess(`OpenSearch domain '${domainName}' deletion initiated`);
165+
}
166+
} catch (e) { printWarning(`Domain cleanup: ${e.message}`); }
167+
168+
// 8. AMP workspace (if tagged with this stack)
169+
try {
170+
const { AmpClient, ListWorkspacesCommand, DeleteWorkspaceCommand } = await import('@aws-sdk/client-amp');
171+
const amp = new AmpClient({ region });
172+
const { workspaces } = await amp.send(new ListWorkspacesCommand({ alias: pipelineName }));
173+
for (const w of workspaces || []) {
174+
if (w.alias === pipelineName) {
175+
await amp.send(new DeleteWorkspaceCommand({ workspaceId: w.workspaceId }));
176+
printSuccess(`AMP workspace '${w.alias}' deleted`);
177+
}
178+
}
179+
} catch (e) { printWarning(`AMP cleanup: ${e.message}`); }
180+
153181
console.error();
154182
printSuccess('Destroy complete');
155-
printInfo('Note: OpenSearch domain and AMP workspace were preserved (shared resources)');
156183
}

0 commit comments

Comments
 (0)