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