Skip to content

Instantly share code, notes, and snippets.

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 jessesanford/1794f7375c1e6ed30968bcfbc666fac7 to your computer and use it in GitHub Desktop.
Save jessesanford/1794f7375c1e6ed30968bcfbc666fac7 to your computer and use it in GitHub Desktop.
Rename AWS Parameter Store Values
require 'json'
# Rename parameter store paths. Takes:
# - parameter store json file path
# - old path
# - new path to use
old_path, new_path, _rest = ARGV
params = `aws ssm get-parameters-by-path --path #{old_path} --with-decryption`
params = JSON.parse(params, object_class: OpenStruct)
params.Parameters.each do |param|
name = param.Name.gsub(old_path, new_path)
value = param.Value.gsub(old_path, new_path)
type = param.Type
json_body = {"Name" => name, "Value" => value, "Type" => type }.to_json
# Assumes default KMS key for 'SecureString' type.
output = `aws ssm put-parameter --cli-input-json '#{json_body}'`
puts output
end
# Run `aws ssm delete-parameters --names ...` to delete old version of parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment