with-aws-creds
A CLI tool to run a command with your AWS credentials set as environment variables.
The tool will set ALL key/values from the selected profile from the AWS Credentials file as environment variables, where:
- The environment variable names are in UPPERCASE
- The profile selected is either
- the one set in the
--aws_profile
argument, or - the one set in the
AWS_PROFILE
environment variable, or - the
default
, or - if non-match, and there is only one profile, then that.
- the one set in the
Usage
Install the tool globally:
npm install -g with-aws-creds
Use the with-aws-creds
command to execute any commands:
with-aws-creds yarn test
Note that when you want to execute a command which has command-line arguments in quotes, set the whole command in apostrophes:
with-aws-creds "node -e \"console.log(process.env.AWS_ACCESS_KEY_ID)\""
Additional properties
If you would like to set additional temporary environment variables to your command, set them right before your command as command-line arguments with values:
with-aws-creds --aws_account_id=123 -- "node -e \"console.log(process.env.AWS_ACCOUNT_ID)\""
# or
# with-aws-creds --aws_account_id 123 -- "node -e \"console.log(process.env.AWS_ACCOUNT_ID)\""
You can also use the --
separator argument to differentiate between the command and the arguments. Using it is optional, but it makes clear, which is the command and where arguments start.
Important! ensure that all parameters you set have a value!
Note that arguments can be set using either underscore (_
) or dash (-
) instead of white spaces, e.g. --aws-profile
.
STS
The tool also allows using AWS STS to assume a given role and use the credentials during command execution. To assume a role and use that, you can use the following command:
with-aws-creds --aws_role=arn-of-the-role -- "node -e \"console.log(process.env.AWS_ACCESS_KEY_ID)\""
If the aws_role
argument is set, then the tool will use the default credentials set on the host machine and will assume the role passed. If the action is successful, then the generated AWS credentials will be set in the environment variables.
More
For detailed documentation see the TypeDocs documentation.