def cfn_cleanup()

in setup/lambda-custom-resource/prepare_dev_package_cr.py [0:0]


def cfn_cleanup():
    """Clean up resources created in the custom resources"""

    LOGGER.info('Deleting role alias if exists')
    try:
        iot_client.delete_role_alias(roleAlias=role_alias)
    except:
        LOGGER.info('Role alias deletion failed, continuing anyways')
    
    LOGGER.info('Deregistering device from edge fleet if exists')
    try:
        sm_client.deregister_devices(
            DeviceFleetName=sm_em_fleet_name,
            DeviceNames=[sm_edge_device_name]
        )
    except:
        LOGGER.info('Device deregistration failed, continuing anyways')

    LOGGER.info('Detaching certificates')
    try:
        cert_arn = iot_client.list_thing_principals(thingName=iot_thing_name)['principals'][0]
        cert_id = cert_arn.split('/')[-1]
        iot_client.detach_policy(policyName=iot_policy_name, target=cert_arn)
        iot_client.detach_thing_principal(thingName=iot_thing_name, principal=cert_arn)
        iot_client.update_certificate(certificateId=cert_id, newStatus='INACTIVE')
        iot_client.delete_certificate(certificateId=cert_id, forceDelete=True)
        iot_client.delete_thing_group(thingGroupName=iot_thing_group_name)
    except:
        LOGGER.info('Detaching certificates failed, continuing anyways')