Forked from sdemontfort/rename-parameter-store-values.rb
Created
July 31, 2019 22:37
-
-
Save jessesanford/1794f7375c1e6ed30968bcfbc666fac7 to your computer and use it in GitHub Desktop.
Rename AWS Parameter Store Values
This file contains 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
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