-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
31 lines (24 loc) · 881 Bytes
/
Rakefile
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
require 'aws-sdk-dynamodb'
require 'date'
MAX_ITEM_COUNT = 25
desc <<HERE
Put multiple items in DynamoDB table (upto a maximum of 25) using batch_write_item
HERE
task :put_item, [:table, :region, :item_count] do |t, args|
table = args.table or raise 'Table name not provided'
region = args.region or raise 'AWS region not provided'
item_count = [args.item_count.to_i || MAX_ITEM_COUNT, MAX_ITEM_COUNT].min
items = 1.upto(item_count).collect do |n|
{put_request: {item: {
"id": "#{DateTime.now.to_s}",
"offset": "#{n}"
}}}
end
client = Aws::DynamoDB::Client.new(region: region)
client.batch_write_item({
request_items: {
"#{table}": items
},
return_item_collection_metrics: "SIZE"
})
end