-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathhello_dynamodb.rb
More file actions
45 lines (36 loc) · 1.19 KB
/
hello_dynamodb.rb
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# snippet-start:[ruby.dynamodb.hello_dynamodb]
require 'aws-sdk-dynamodb'
require 'logger'
# DynamoDBManager is a class responsible for managing DynamoDB operations
# such as listing all tables in the current AWS account.
class DynamoDBManager
def initialize(client)
@client = client
@logger = Logger.new($stdout)
end
# Lists and prints all DynamoDB tables in the current AWS account.
def list_tables
@logger.info('Here are the DynamoDB tables in your account:')
paginator = @client.list_tables(limit: 10)
table_names = []
paginator.each_page do |page|
page.table_names.each do |table_name|
@logger.info("- #{table_name}")
table_names << table_name
end
end
if table_names.empty?
@logger.info("You don't have any DynamoDB tables in your account.")
else
@logger.info("\nFound #{table_names.length} tables.")
end
end
end
if $PROGRAM_NAME == __FILE__
dynamodb_client = Aws::DynamoDB::Client.new
manager = DynamoDBManager.new(dynamodb_client)
manager.list_tables
end
# snippet-end:[ruby.dynamodb.hello_dynamodb]