Usar StopModel com um SDK da AWS - Exemplos de código do AWS SDK

Há mais exemplos do AWS SDK disponíveis no repositório do GitHub Documento de Exemplos do AWS SDK.

Usar StopModel com um SDK da AWS

O código de exemplo a seguir mostra como usar StopModel.

Para obter mais informações, consulte Interromper o modelo.

Python
SDK para Python (Boto3).
nota

Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

class Hosting: @staticmethod def stop_model(lookoutvision_client, project_name, model_version): """ Stops a running Lookout for Vision Model. :param lookoutvision_client: A Boto3 Lookout for Vision client. :param project_name: The name of the project that contains the version of the model that you want to stop hosting. :param model_version: The version of the model that you want to stop hosting. """ try: logger.info("Stopping model version %s for %s", model_version, project_name) response = lookoutvision_client.stop_model( ProjectName=project_name, ModelVersion=model_version ) logger.info("Stopping hosting...") status = response["Status"] finished = False # Wait until stopped or failed. while finished is False: model_description = lookoutvision_client.describe_model( ProjectName=project_name, ModelVersion=model_version ) status = model_description["ModelDescription"]["Status"] if status == "STOPPING_HOSTING": logger.info("Host stopping in progress...") time.sleep(10) continue if status == "TRAINED": logger.info("Model is no longer hosted.") finished = True continue logger.info("Failed to stop model: %s ", status) finished = True if status != "TRAINED": logger.error("Error stopping model: %s", status) raise Exception(f"Error stopping model: {status}") except ClientError: logger.exception("Couldn't stop hosting model.") raise
  • Consulte detalhes da API em StopModel na Referência da API AWS SDK para Python (Boto3).