Last active
September 30, 2022 02:53
-
-
Save miry/9e2a2f32285381dad96528210533d5c6 to your computer and use it in GitHub Desktop.
Sample to get all items from DynamoDB table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'aws-sdk-dynamodb' | |
require 'hirb' | |
# NOTICE: Authorize via https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html | |
dynamodb = Aws::DynamoDB::Client.new | |
scan_opts = { table_name: '<TABLE_NAME>' } | |
items = [] | |
total = 0 | |
loop do | |
response = dynamodb.scan(scan_opts) | |
items << response.items | |
# TODO: Here you can filter or process items | |
break unless (last = response.last_evaluated_key) | |
scan_opts.merge!(exclusive_start_key: last) | |
end | |
puts Hirb::Helpers::AutoTable.render(items, max_width: 220) | |
puts "Total: #{total}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source 'https://rubygems.org' | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem 'aws-sdk-dynamodb' | |
gem 'hirb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment