Skip to content

Instantly share code, notes, and snippets.

@ojacques
Last active November 17, 2022 20:25
Show Gist options
  • Save ojacques/b38fe13afc699da1e3add45b65502b5d to your computer and use it in GitHub Desktop.
Save ojacques/b38fe13afc699da1e3add45b65502b5d to your computer and use it in GitHub Desktop.
Export aws ssm get-parameters-by-path results as environment variables with jq

Export all AWS SSM Parameters retrieved from a given path as environment variables

Example:

I have the following SSM parameters:

  • /codepipeline/deploy_prod with value "v1.2.0"
  • /codepipeline/deploy_preprod with value "v1.1.1"
  • /codepipeline/deploy_sandbox with value "a0582a5fa7fff7361b18581d04d222a35cceb264"

The following environment variables will be exported:

_CODEPIPELINE_DEPLOY_PROD=v1.2.0
_CODEPIPELINE_DEPLOY_PREPROD=v1.1.1
_CODEPIPELINE_DEPLOY_SANDBOX_GREEN=a0582a5fa7fff7361b18581d04d222a35cceb264
#!/bin/bash
for s in $(aws ssm get-parameters-by-path --path '/codepipeline/' --region eu-west-1 --query "Parameters[].{Key:Name,Val:Value}" | jq -r 'map("\(.Key|ascii_upcase)=\(.Val|tostring)") | .[] |= gsub("(/|-)";"_") | .[]'); do
echo export $s
export $s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment