Giter VIP home page Giter VIP logo

Comments (2)

tim-finnigan avatar tim-finnigan commented on June 4, 2024

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 --output dotenv would likely not be considered because --output is a global parameter used for general formatting of outputs (json, table, text) and I don't think this use case is common or general enough to warrant a new output format.

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.

from aws-cli.

github-actions avatar github-actions commented on June 4, 2024

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

from aws-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.