使用获取有关 Amazon Keyspaces 密钥空间的数据AmazonSDK - Amazon Keyspaces (for Apache Cassandra)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用获取有关 Amazon Keyspaces 密钥空间的数据AmazonSDK

以下代码示例显示如何获取 Amazon Keyspaces 密钥空间的相关数据。

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

有关详细信息,请参阅。 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

/// <summary> /// Get data about a keyspace. /// </summary> /// <param name="keyspaceName">The name of the keyspace.</param> /// <returns>The Amazon Resource Name (ARN) of the keyspace.</returns> public async Task<string> GetKeyspace(string keyspaceName) { var response = await _amazonKeyspaces.GetKeyspaceAsync( new GetKeyspaceRequest { KeyspaceName = keyspaceName }); return response.ResourceArn; }
  • 有关 API 的详细信息,请参阅GetKeyspaceAmazon SDK for .NETAPI 参考内容

Java
SDK for Java 2.x
注意

有关详细信息,请参阅。 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void checkKeyspaceExistence(KeyspacesClient keyClient, String keyspaceName) { try { GetKeyspaceRequest keyspaceRequest = GetKeyspaceRequest.builder() .keyspaceName(keyspaceName) .build(); GetKeyspaceResponse response = keyClient.getKeyspace(keyspaceRequest); String name = response.keyspaceName(); System.out.println("The "+ name+ " KeySpace is ready"); } catch (KeyspacesException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关 API 的详细信息,请参阅GetKeyspaceAmazon SDK for Java 2.xAPI 参考内容

Kotlin
SDK for Kotlin
注意

这是适用于预览版中功能的预发行文档。本文档随时可能更改。

注意

查看更多内容 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

suspend fun checkKeyspaceExistence(keyspaceNameVal: String?) { val keyspaceRequest = GetKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response: GetKeyspaceResponse = keyClient.getKeyspace(keyspaceRequest) val name = response.keyspaceName println("The $name KeySpace is ready") } }
  • 有关详细信息,请参阅。GetKeyspaceAmazonKotlin 开发工具包 API 参考

Python
适用于 Python (Boto3) 的 SDK
注意

查看更多内容 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

class KeyspaceWrapper: """Encapsulates Amazon Keyspaces (for Apache Cassandra) keyspace and table actions.""" def __init__(self, keyspaces_client): """ :param keyspaces_client: A Boto3 Amazon Keyspaces client. """ self.keyspaces_client = keyspaces_client self.ks_name = None self.ks_arn = None self.table_name = None @classmethod def from_client(cls): keyspaces_client = boto3.client('keyspaces') return cls(keyspaces_client) def exists_keyspace(self, name): """ Checks whether a keyspace exists. :param name: The name of the keyspace to look up. :return: True when the keyspace exists. Otherwise, False. """ try: response = self.keyspaces_client.get_keyspace(keyspaceName=name) self.ks_name = response['keyspaceName'] self.ks_arn = response['resourceArn'] exists = True except ClientError as err: if err.response['Error']['Code'] == 'ResourceNotFoundException': logger.info("Keyspace %s does not exist.", name) exists = False else: logger.error( "Couldn't verify %s exists. Here's why: %s: %s", name, err.response['Error']['Code'], err.response['Error']['Message']) raise return exists
  • 有关详细信息,请参阅。GetKeyspaceAmazonPython 版 SDK (Boto3) API 参考

有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将亚马逊Keyspaces 与 S Amazon DK 一起使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。