description: Setup document for SQL Server License Tracking Solution schemaVersion: '0.3' assumeRole: '{{ AutomationAssumeRole }}' parameters: AutomationAssumeRole: type: String description: The IAM role required to execute this document (select SQLServerLTS-SystemsManagerAutomationAdministrationRole from the drop-down if you deployed this solution using CloudFormation) mainSteps: - name: deleteCustomInventory description: 'This clean up step deletes all the metadata associated with the custom inventory type created for MSSQL [Custom:SQLServer] on all the EC2 instances.' action: 'aws:executeScript' inputs: Runtime: python3.7 Handler: script_handler Script: |- import sys import boto3 import json import botocore import time def script_handler(events, context): client = boto3.client('ssm') get_inventory_response = client.get_inventory_schema( TypeName='Custom:SQLServer' ) print(get_inventory_response) if get_inventory_response['Schemas']: delete_inventory_response = client.delete_inventory( TypeName='Custom:SQLServer', SchemaDeleteOption='DeleteSchema' ) deletion_id = delete_inventory_response['DeletionId'] wait_loop = True while wait_loop == True: describe_inventory_deletions_response = client.describe_inventory_deletions( DeletionId=deletion_id ) if describe_inventory_deletions_response['InventoryDeletions']: if describe_inventory_deletions_response['InventoryDeletions'][0]['LastStatus'] == "Complete": status = "Custom:SQLServer schema has been deleted successfuly. DeletionID: "+deletion_id wait_loop = False break else: time.sleep(60) else: status = "Custom:SQLServer type doesn't exist in the Inventory so continuing to the next step." return {'message': status} outputs: - Name: result Selector: $.Payload.message Type: String isCritical: true onFailure: Abort isEnd: true