Skip to content

Instantly share code, notes, and snippets.

@dennismclaugh
Last active April 8, 2019 21:12
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 dennismclaugh/7d6d12ddc94725b6a1d90e9bc458bc9b to your computer and use it in GitHub Desktop.
Save dennismclaugh/7d6d12ddc94725b6a1d90e9bc458bc9b to your computer and use it in GitHub Desktop.
Short script that demonstrates how to save secrets up in AWS Parameter Store.
# This script will automatically add and update secrets in the AWS Parameter Store.
# Example: "./set_parameters_to_aws.sh test_environment.txt" will store the secrets at path /WebDriver_Tests/my_parameters
#
# Check if an input file was specified
if [ $# -eq 0 ] || [ ! -f $1 ]; then
echo
echo "No test environment specified or config file not found. Example usage '$ set_parameters_to_aws.sh tesT_environment.txt'"
echo
exit 1
fi
# Strips away everything leaving the name of the input filename (in case you use a full path)
temp=$(sed -e 's#.*/\(\)#\1#' <<< $1)
test_env=$(echo "${temp%%.*}")
# We want to break each line at the "=" to get our key and our value
IFS='='
while read -r key value;
do
# Skip comment lines
if [[ $key != "#"* ]]; then
cat >./file.json <<EOF
{
"Type": "SecureString",
"Name": "/WebDriver_Tests/${test_env}/${key}",
"Value": "${value}",
"KeyId": "alias/test-integration-secrets",
"Overwrite": true
}
EOF
echo "Saving parameter: " $key
aws ssm put-parameter --cli-input-json file://file.json
rm file.json
fi
done < $1
echo
echo "Done saving secrets to AWS."
echo "You can find them at https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Parameters:Path=%5BOneLevel%5D/WebDriver_Tests/${test_env};sort=Name$/"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment