Skip to content

Instantly share code, notes, and snippets.

@todgru
Forked from wyllie/parse_ini.sh
Created Feb 9, 2021
Embed
What would you like to do?
Parse aws credentials file in bash
#!/usr/bin/env bash
INI_FILE=~/.aws/credentials
while IFS=' = ' read key value
do
if [[ $key == \[*] ]]; then
section=$key
elif [[ $value ]] && [[ $section == '[default]' ]]; then
if [[ $key == 'aws_access_key_id' ]]; then
AWS_ACCESS_KEY_ID=$value
elif [[ $key == 'aws_secret_access_key' ]]; then
AWS_SECRET_ACCESS_KEY=$value
fi
fi
done < $INI_FILE
echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY
@todgru

This comment has been minimized.

Copy link
Owner Author

@todgru todgru commented Feb 9, 2021

If available and depending on use case, the aws cli tool can retrieve the values, aws configure get varname [--profile profile-name]

aws --profile default configure get aws_access_key_id
aws --profile default configure get aws_secret_access_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment