New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dotenv output format for aws ssm get-parameters-by-path
#8599
Comments
Thanks for the feature request regarding the get-parameters-by-path command. Here is related documentation on AWS CLI command line options. The request to add a The SSM service team owns the underlying GetParametersByPath API that is used here, so we could forward a feature request to them to provide the ability to return parameters in dotenv format. I'll also share a utility script that I think accomplishes what you're trying to do: #!/bin/bash
# Set the parameter path prefix
PARAMETER_PATH="/"
# Fetch parameters from the Parameter Store
PARAMETERS=$(aws ssm get-parameters-by-path --path "$PARAMETER_PATH" --recursive --with-decryption --query 'Parameters[*].[Name,Value]' --output text)
DOTENV_LINES=$(echo "$PARAMETERS" | awk -F $'\t' '{ printf "%s=%s\n", $1, $2 }')
# Write the dotenv lines to a file
echo "$DOTENV_LINES" > .env
echo "Environment variables exported to .env" Also in a Boto3 script: import boto3
# Set up AWS credentials/configurations
session = boto3.Session()
ssm_client = session.client('ssm')
# Define the parameter path prefix
parameter_path = '/'
# Fetch parameters from the Parameter Store
response = ssm_client.get_parameters_by_path(Path=parameter_path, Recursive=True, WithDecryption=True)
# Format parameters in dotenv format
dotenv_lines = []
for parameter in response['Parameters']:
key = parameter['Name'].split('/')[-1]
value = parameter['Value']
dotenv_lines.append(f"{key}={value}")
# Write dotenv lines to a file
dotenv_file = '.env'
with open(dotenv_file, 'w') as f:
f.write('\n'.join(dotenv_lines))
print(f"Environment variables exported to {dotenv_file}") Hope that helps — please let us know if you'd also like us to reach out to the SSM team regarding this feature request. |
Describe the feature
Add a
--dotenv
flag (or maybe an--output dotenv
format option) to format the output of theget-parameters-by-path
command in dotenv format.Use Case
Environment variables are often stored in the SSM Parameter Store. Fetching them out of the store and formatting them in dotenv format is common but not trivial and requires either many steps or a very complicated chain of terminal commands. The dotenv format is widely adopted by tools and mainstream IDEs for configuring environment variables for developers.
Proposed Solution
No response
Other Information
Use awsparams with the
--dotenv
flagOR with linux native tools and the aws cli
Acknowledgements
CLI version used
aws-cli/2.12.6 Python/3.11.4 Darwin/23.1.0 exe/x86_64 prompt/off
Environment details (OS name and version, etc.)
macOS 14.1.2
The text was updated successfully, but these errors were encountered: