DEV Community

Rafaf Tahsin
Rafaf Tahsin

Posted on

aws cred to env

Sometimes it's tidy to export aws credentials manually. It can be done by the following script

#!/bin/bash

echo "# Environment for AWS profile '$1'"
export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id --profile $1)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key --profile $1)
export AWS_DEFAULT_REGION=$(aws configure get region --profile $1)
Enter fullscreen mode Exit fullscreen mode

source the script and you are done.

Note:

Saving script as script.sh and calling it with ./script.sh won't work. Need to source it like source script.sh or . script.sh.

Inspired by https://gist.github.com/mjul/f93ee7d144c5090e6e3c463f5f312587

Top comments (0)