diff --git a/bin/service/get-environment-variable b/bin/service/get-environment-variable new file mode 100755 index 0000000..34cc355 --- /dev/null +++ b/bin/service/get-environment-variable @@ -0,0 +1,60 @@ +#!/bin/bash + +# exit on failures +set -e +set -o pipefail + +usage() { + echo "Usage: $(basename "$0") [OPTIONS]" 1>&2 + echo "This command can set environment variables for a service" + echo " -h - help" + echo " -i - infrastructure name" + echo " -s - service name " + echo " -e - environment name (e.g. 'staging' or 'prod')" + echo " -k - key e.g SMTP_HOST" + exit 1 +} + +if [ $# -lt 1 ] +then + usage +fi + +while getopts "i:e:s:k:h" opt; do + case $opt in + i) + INFRASTRUCTURE_NAME=$OPTARG + ;; + e) + ENVIRONMENT=$OPTARG + ;; + s) + SERVICE_NAME=$OPTARG + ;; + k) + KEY=$OPTARG + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +if [[ + -z "$INFRASTRUCTURE_NAME" + || -z "$SERVICE_NAME" + || -z "$ENVIRONMENT" + || -z "$KEY" +]] +then + usage +fi + +echo "==> getting environment variable $KEY for $INFRASTRUCTURE_NAME/$SERVICE_NAME/$ENVIRONMENT" + +aws ssm get-parameter --with-decryption \ + --name "/$INFRASTRUCTURE_NAME/$SERVICE_NAME/$ENVIRONMENT/$KEY" \ + | jq -r '.Parameter.Value'