AWS SDK GetControlOperationで を使用する - AWS SDK コードの例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK GetControlOperationで を使用する

次のサンプルコードは、GetControlOperation を使用する方法を説明しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

.NET
SDK for .NET (v4)
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/// <summary> /// Get the status of a control operation. /// </summary> /// <param name="operationId">The ID of the control operation.</param> /// <returns>The operation status.</returns> public async Task<ControlOperationStatus> GetControlOperationAsync(string operationId) { try { var request = new GetControlOperationRequest { OperationIdentifier = operationId }; var response = await _controlTowerService.GetControlOperationAsync(request); return response.ControlOperation.Status; } catch (Amazon.ControlTower.Model.ResourceNotFoundException) { Console.WriteLine("Operation not found."); throw; } catch (AmazonControlTowerException ex) { Console.WriteLine($"Couldn't get control operation status. Here's why: {ex.ErrorCode}: {ex.Message}"); throw; } }
  • API の詳細については、「AWS SDK for .NET API リファレンス」の「GetControlOperation」を参照してください。

Java
SDK for Java 2.x
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/** * Gets the status of a control operation. * * @param operationIdentifier the identifier of the operation * @return the operation status * @throws ControlTowerException if a service-specific error occurs * @throws SdkException if an SDK error occurs */ public CompletableFuture<ControlOperationStatus> getControlOperationAsync( String operationIdentifier) { GetControlOperationRequest request = GetControlOperationRequest.builder() .operationIdentifier(operationIdentifier) .build(); return getAsyncClient().getControlOperation(request) .whenComplete((response, exception) -> { if (exception != null) { Throwable cause = exception.getCause() != null ? exception.getCause() : exception; if (cause instanceof ControlTowerException e) { String errorCode = e.awsErrorDetails().errorCode(); if ("ResourceNotFoundException".equals(errorCode)) { throw new CompletionException( "Control operation not found: %s".formatted(e.getMessage()), e ); } throw new CompletionException( "Error getting control operation status: %s".formatted(e.getMessage()), e ); } if (cause instanceof SdkException) { throw new CompletionException( "SDK error getting control operation status: %s".formatted(cause.getMessage()), cause ); } throw new CompletionException("Failed to get control operation status", cause); } }) .thenApply(response -> response.controlOperation().status()); }
  • API の詳細については、「AWS SDK for Java 2.x API リファレンス」の「GetControlOperation」を参照してください。

Python
SDK for Python (Boto3)
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

class ControlTowerWrapper: """Encapsulates AWS Control Tower and Control Catalog functionality.""" def __init__( self, controltower_client: boto3.client, controlcatalog_client: boto3.client ): """ :param controltower_client: A Boto3 Amazon ControlTower client. :param controlcatalog_client: A Boto3 Amazon ControlCatalog client. """ self.controltower_client = controltower_client self.controlcatalog_client = controlcatalog_client @classmethod def from_client(cls): controltower_client = boto3.client("controltower") controlcatalog_client = boto3.client("controlcatalog") return cls(controltower_client, controlcatalog_client) def get_control_operation(self, operation_id: str): """ Gets the status of a control operation. :param operation_id: The ID of the control operation. :return: The operation status. :raises ClientError: If getting the operation status fails. """ try: response = self.controltower_client.get_control_operation( operationIdentifier=operation_id ) return response["controlOperation"]["status"] except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Operation not found.") else: logger.error( "Couldn't get control operation status. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • API の詳細については、AWS SDK for Python (Boto3) API リファレンスの「GetControlOperation」を参照してください。