D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Utilisation GetControlOperation
avec un AWS SDK
Les exemples de code suivants illustrent comment utiliser GetControlOperation
.
Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :
- .NET
-
- SDK pour .NET (v4)
-
/// <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;
}
}
- Python
-
- SDK pour Python (Boto3)
-
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