env-aws-params
env-aws-params copied to clipboard
Add option to not fail when region and prefix are not set
I would like env-aws-params to run the target command as-is if the prefix and region are not set.
Conditions
- Neither the
--aws-region
flag nor theAWS_REGION
environment variable are set. - Neither the
--prefix
flag nor thePARAMS_PREFIX
environment variable are set.
Current Behavior Program aborts and does execute target command.
$ env-aws-params service
ERROR: prefix is required
Desired Behavior Program warns of missing variables and executes target command without retrieving variables.
$ env-aws-params --ignore-no-config service
WARNING: SSM variables not set
Why
I'm conditionally using env-aws-params in a Docker entrypoint script to execute the Docker command as-is if neither the PARAMS_PREFIX
and AWS_REGION
variables are set. This allows me to use the same container in both production and a fully local environment; the container won't reach out to SSM unless both previous mentions env vars are set.
The entrypoint script is fairly generic as it only inspects variables used by env-aws-params. However, it ends up becoming a copy/paste snippet of code that gets carried around to multiple projects. It also must be an external file to be able to safely pass "$@"
to it.
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
#!/usr/bin/env sh
if [ -n "${PARAMS_PREFIX}" ] && [ -n "${AWS_REGION}" ]; then
exec env-aws-params "$@"
else
exec "$@"
fi
Solution Add a command-line flag to env-aws-params to do essentially the same thing.
ENTRYPOINT ["env-aws-params", "--ignore-no-config"]
I don't have a preference how this option is set; the name --ignore-no-config
was picked without much thought put into it.
If you're open to including this, I'll glady take on development.