搭DescribeStatement配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeStatement配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用DescribeStatement

Java
SDK對於爪哇 2.x
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void checkStatement(RedshiftDataClient redshiftDataClient, String sqlId) { try { DescribeStatementRequest statementRequest = DescribeStatementRequest.builder() .id(sqlId) .build(); String status; while (true) { DescribeStatementResponse response = redshiftDataClient.describeStatement(statementRequest); status = response.statusAsString(); System.out.println("..." + status); if (status.compareTo("FAILED") == 0 ) { System.out.println("The Query Failed. Ending program"); System.exit(1); } else if (status.compareTo("FINISHED") == 0) { break; } TimeUnit.SECONDS.sleep(1); } System.out.println("The statement is finished!"); } catch (RedshiftDataException | InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考DescribeStatement中的。

Python
SDK對於 Python(肉毒桿菌 3)
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

class RedshiftDataWrapper: """Encapsulates Amazon Redshift data.""" def __init__(self, client): """ :param client: A Boto3 RedshiftDataWrapper client. """ self.client = client def describe_statement(self, statement_id): """ Describes a SQL statement. :param statement_id: The SQL statement identifier. :return: The SQL statement result. """ try: response = self.client.describe_statement(Id=statement_id) return response except ClientError as err: logging.error( "Couldn't describe statement. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise

下面的代碼實例化對 RedshiftDataWrapper 象。

client = boto3.client("redshift-data") redshift_data_wrapper = RedshiftDataWrapper(client)
  • 如需詳API細資訊,請參閱DescribeStatementAWS SDK的〈〉以取得 Python (Boto3) API 參考資料。