Skip to content

Instantly share code, notes, and snippets.

@etipton
Last active September 6, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etipton/4cc4a5e6146b092dafe7 to your computer and use it in GitHub Desktop.
Save etipton/4cc4a5e6146b092dafe7 to your computer and use it in GitHub Desktop.
Convert downloaded AWS access creds to env vars
#!/usr/bin/env ruby
# Use ENV var if needed, e.g. ".zshenv"
shell_init_file = File.expand_path(ENV['SHELL_INIT_FILE'] || '~/.bash_profile')
aws_creds_file = File.expand_path(ENV['CREDS_FILE'] || '~/Downloads/credentials.csv')
require 'csv'
csv = CSV.parse(File.read(aws_creds_file), headers: true)
row = csv.first.to_hash
File.open(shell_init_file, 'a') do |f|
f.write ["",
"export AWS_ACCESS_KEY_ID=#{row['Access Key Id']}",
"export AWS_SECRET_ACCESS_KEY=#{row['Secret Access Key']}"
].join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment