Export AWS SSM Parameter Store as Environment Variables with Bash
This bash script exports all SSM parameters under a given path as environment variables and appends the export statements to the ~/.bashrc

Search for a command to run...
This bash script exports all SSM parameters under a given path as environment variables and appends the export statements to the ~/.bashrc

No comments yet. Be the first to comment.
A practical guide to Deepsec, Vercel's security harness: how to configure it correctly with your Claude Code subscription, run scans on your codebase, troubleshoot common issues, and triage findings effectively.
Guía práctica de deepsec Guía completa para usar deepsec — el security harness de Vercel — entendiendo qué hace cada comando, cómo configurarlo correctamente para usar tu suscripción de Claude Code (e
Using Grafana, Prometheus, Node Exporter, cAdvisor, and Loki, Exposed via NGINX
Jupyter Lite Notebook is an incredibly versatile tool for working with code and data interactively and collaboratively.

Ultra-Light HTTP Server with Busybox HTTPD Applet Description: This Docker image is designed to provide an ultra-lightweight HTTP server optimized for efficiently serving static files. It is based on the Busybox system and utilizes the Applet HTTPD f...

aws ssm put-parameter --name "/my-app/my-param-name" --value "my-param-value" --type "String"
Replace "/my-app/my-param-name" with the desired path and name for the parameter. Note that the path must begin with a forward slash (/) and can include multiple levels separated by forward slashes. Also, if the path does not exist, the put-parameter command will create it automatically.
Make sure you have permission to create parameters in the SSM parameter store, and specify any necessary additional parameters like --region or --profile.
The script sets some parameters like APP, SERVICE, ENVIRONMENT, and REGION. These variables are used to construct the SSM path to retrieve the parameters.
The script uses the aws ssm get-parameters-by-path command to retrieve all SSM parameter names under the given path. Then, it loops through each parameter and exports it as an environment variable. The script also appends the export statements to the ~/.bashrc file so that they persist on future logins.
Finally, the script reloads the ~/.bashrc file with the source command.
nano export-ssm-params.sh
#or
vim export-ssm-params.sh
Copy/paste the following code.
Here's the script:
#!/bin/bash
# This script will export all SSM parameters under a given path as environment variables
# It will also append the export statements to the ~/.bashrc file so that they are available on future logins
# Set some parameters
APP="myapp"
SERVICE="api"
ENVIRONMENT="production"
REGION="us-east-1"
# Set the SSM path
SSM_PATH="/$APP/$SERVICE/$ENVIRONMENT"
# Get all SSM parameter names under the given path
SSM_PARAMETER_NAMES=$(aws ssm get-parameters-by-path \
--region $REGION \
--path "$SSM_PATH" \
--recursive \
--with-decryption \
--query 'Parameters[].Name' \
--output text)
# Loop through each parameter and export it as an environment variable
for name in $SSM_PARAMETER_NAMES; do
value=$(aws ssm get-parameter \
--region $REGION \
--name $name \
--with-decryption \
--query 'Parameter.Value' \
--output text)
if [ ! -z "$name" ] && [ ! -z "$value" ]; then
name=$(echo $name | awk -F/ '{print toupper($NF)}')
export "$name"="$value"
echo "Exported variable: $name=$value"
echo "export $name=$value" >> ~/.bashrc
fi
done
# Reload the bashrc file
source ~/.bashrc
To use this script, you need to have the AWS client (awscli) installed and configured to authenticate to an AWS account. Then, simply execute the script with Bash in a terminal.
You can save the script in a file with .sh extension, for example export-ssm-params.sh.
nano export-ssm-params.sh
#or
vim export-ssm-params.sh
Don't forget add execution permission
chmod +x export-ssm-params.sh
Now you can run the script with the following command:
bash export-ssm-params.sh
#or
./export-ssm-params.sh
In summary, this bash script is useful to export AWS Systems Manager parameters as environment variables. This can be helpful in different situations, for example, to avoid the need to repeatedly call the AWS API to get the parameter values.
Additionally, the script also adds the export statements to the ~/.bashrc file, meaning that the environment variables will be available in future Bash terminal sessions.