Skip to content

Instantly share code, notes, and snippets.

@dvejmz

dvejmz/asm.sh

Last active Jun 11, 2020
Embed
What would you like to do?
AWS Secrets Manager CLI wrapper
#!/usr/bin/env bash
AWS_REGION=<region>
AWS_PROFILE=<profile>
export AWS_REGION
export AWS_PROFILE
SECRET_PATH="$1"
SECRET_KEY=$2
if [[ "${SECRET_PATH}" =~ /$ ]]; then
aws secretsmanager list-secrets \
| jq ".[][].Name | match(\"${SECRET_PATH}.*\"; \"g\") | .string"
exit 0
fi
if [[ ! -z ${SECRET_KEY} ]]; then
aws secretsmanager get-secret-value \
--secret-id "${SECRET_PATH}" \
| jq ".SecretString | fromjson" \
| jq -r ".${SECRET_KEY}"
exit 0
fi
aws secretsmanager get-secret-value \
--secret-id "${SECRET_PATH}" \
| jq ".SecretString | fromjson"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.