Created
November 9, 2018 13:41
-
-
Save EricLondon/d8e5e39ba5cffbae1462de8430bbfb98 to your computer and use it in GitHub Desktop.
Ruby populate person objects in S3
This file contains hidden or 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
person-data |
This file contains hidden or 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
ruby-2.5.3 |
This file contains hidden or 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
source 'https://rubygems.org' | |
git_source(:github) do |repo_name| | |
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") | |
"https://github.com/#{repo_name}.git" | |
end | |
gem 'aws-sdk-core', '~> 3' | |
gem 'aws-sdk-s3', '~> 1' | |
gem 'faker' | |
gem 'pry' |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'aws-sdk-s3' | |
require 'faker' | |
require 'pry' | |
require 'json' | |
s3 = Aws::S3::Resource.new(region: 'us-east-1') | |
s3_bucket = 'eric20181029' | |
file_path = './person.json' | |
file_count = 5_000 | |
(1..file_count).each do |person_id| | |
person_object = { | |
PersonID: person_id, | |
demographics: [ | |
{ | |
Name: Faker::Name.name, | |
Sex: %w(M F).sample, | |
Address1: Faker::Address.street_address, | |
City: Faker::Address.city, | |
State: Faker::Address.state_abbr, | |
Zip: Faker::Address.zip, | |
PhoneNumber: Faker::PhoneNumber.phone_number | |
} | |
] | |
} | |
File.open(file_path, 'w') { |file| file.write(person_object.to_json) } | |
s3_key = "person/#{person_id}.json" | |
s3_object = s3.bucket(s3_bucket).object(s3_key) | |
s3_object.upload_file(file_path) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment