π Fetch secrets from AWS Secrets Manager and generate a .json file β to use with AWS SAM for local development.
Before running the script, make sure you have:
- AWS CLI installed and configured with the correct
--profile. jqinstalled. Install it via Homebrew:brew install jq
Run the script locally:
bash bin/fetch-secrets.sh <secrets.json> <output.json> [--region eu-central-1] [--profile tv2-cms-dev]You can also run the script directly without cloning:
curl -sSL https://raw.githubusercontent.com/tv2/npp-aws-sam-local-secrets-public/main/bin/fetch-secrets.sh | bash -s -- <secrets.json> <output.json> [--region ...] [--profile ...]Example:
# Fetch secrets and generate local.env.json from local.secrets.json
curl -sSL https://raw.githubusercontent.com/tv2/npp-aws-sam-local-secrets-public/main/bin/fetch-secrets.sh \
| bash -s -- local.secrets.json local.env.json --region eu-central-1 --profile tv2-cms-devSee example.secrets.json for the expected format of the input file.
To use the generated secrets with AWS SAM, pass the output file using --env-vars:
sam local start-api --env-vars local.env.jsonThe generated secrets file (local.env.json) contains real secret values. Always add it to .gitignore so itβs never committed to Git! Example .gitignore:
# Local AWS secrets
local.env.json
β Thatβs it β happy secret fetching!