删除 Amazon DynamoDB 表 - 适用于 Ruby 的 Amazon 开发工具包
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

删除 Amazon DynamoDB 表

以下示例删除 us-west-2 区域中的 Movies 表。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 require 'aws-sdk-dynamodb' # Deletes a table in Amazon DynamoDB. # # @param dynamodb_client [Aws::DynamoDB::Client] An initialized # Amazon DynamoDB client. # @param table_name [String] The name of the table to delete. # @return [Boolean] true if the table was deleted; otherwise, false. # @example # ext 1 unless table_deleted?( # Aws::DynamoDB::Client.new(region, 'us-west-2'), # 'Movies' # ) def table_deleted?(dynamodb_client, table_name) dynamodb_client.delete_table(table_name: table_name) true rescue StandardError => e puts "Error deleting table: #{e.message}" false end # Full example call: def run_me region = 'us-west-2' table_name = 'Movies' dynamodb_client = Aws::DynamoDB::Client.new(region: region) puts "Deleting table '#{table_name}'..." if table_deleted?(dynamodb_client, table_name) puts 'Table deleted.' else puts 'Table not deleted.' end end run_me if $PROGRAM_NAME == __FILE__

请参阅 GitHub 上的完整示例