Skip to content

Instantly share code, notes, and snippets.

@miry
Last active September 30, 2022 02:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miry/9e2a2f32285381dad96528210533d5c6 to your computer and use it in GitHub Desktop.
Save miry/9e2a2f32285381dad96528210533d5c6 to your computer and use it in GitHub Desktop.
Sample to get all items from DynamoDB table
# 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}"
# 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