Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created May 5, 2020 21:13
Show Gist options
  • Save ajsharp/cf37fd27bbc0b1729c281898c6d99b5f to your computer and use it in GitHub Desktop.
Save ajsharp/cf37fd27bbc0b1729c281898c6d99b5f to your computer and use it in GitHub Desktop.
Migrate the environment variables from one elastic beanstalk environment to another
#!/usr/bin/env ruby
# Usage: migrate-eb-env FROM_ENV TO_ENV
from, to = ARGV
if !from || !to
$stderr.puts "FROM_ENV and TO_ENV are required"
exit(1)
end
raw_env = `eb printenv #{from}`.strip.gsub(' ', '').split("\n")
raw_env.shift # remove the "Environment Variables:" line
env = raw_env
# filter out secret values
env = env.select do |e|
found = e.match(/[*]{3}/)
if found
puts "Secret value found=#{e}"
end
!found
end
# puts env
setenv = env.join(' ')
# puts "setenv=#{setenv}"
`eb setenv #{setenv} -e #{to}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment