Minimal AWS MFA helper for the CLI.
aws-mfa-go refreshes temporary AWS credentials using MFA and writes them to ~/.aws/credentials.
Inspired by broamski/aws-mfa, implemented in Go as a single binary.
- Install:
brew install jlis/tap/aws-mfa-go- Add long-term credentials to
~/.aws/credentials:
[prod-long-term]
aws_access_key_id = YOUR_LONGTERM_KEY_ID
aws_secret_access_key = YOUR_LONGTERM_SECRET
aws_mfa_device = arn:aws:iam::123456789012:mfa/your-user- Run:
aws-mfa-go --profile prodYou’ll be prompted for your 6-digit MFA code, and short-term credentials will be written to [prod].
- Reads long-term credentials from
~/.aws/credentials - Prompts for an MFA token (or accepts
--token) - Calls AWS STS
GetSessionToken - Writes short-term credentials back into
~/.aws/credentials - Skips STS calls when existing short-term credentials are still valid (unless
--force)
brew install jlis/tap/aws-mfa-gobrew update
brew upgrade aws-mfa-gogo install github.com/jlis/aws-mfa-go/cmd/aws-mfa-go@latest[prod-long-term]
aws_access_key_id = YOUR_LONGTERM_KEY_ID
aws_secret_access_key = YOUR_LONGTERM_SECRET
aws_mfa_device = arn:aws:iam::123456789012:mfa/your-userRequired keys in your long-term section:
aws_access_key_idaws_secret_access_keyaws_mfa_device
Short-term credentials are written automatically to [<profile>] (for example [prod]).
Refresh credentials:
aws-mfa-go --profile prodForce refresh:
aws-mfa-go --profile prod --forceNon-interactive:
aws-mfa-go --profile prod --token 123456Show version:
aws-mfa-go --versionaws-mfa-go uses:
flags > environment variables > ~/.aws/credentials values > defaults
Environment variables:
AWS_PROFILEMFA_DEVICEMFA_STS_DURATIONAWS_REGION/AWS_DEFAULT_REGION(defaults tous-east-1)
By default:
- long-term section:
<profile>-long-term - short-term section:
<profile>
Override this with:
--long-term-suffix(defaultlong-term, usenoneto use<profile>)--short-term-suffix(defaultnone, when set uses<profile>-<suffix>)
Example:
aws-mfa-go --profile myorg --long-term-suffix none --short-term-suffix production
aws-mfa-go --profile myorg --long-term-suffix none --short-term-suffix stagingThis writes short-term credentials to [myorg-production] and [myorg-staging], while reading long-term credentials from [myorg].
Build from local checkout:
make build
./aws-mfa-go --helpRun tests:
make testRun linter:
make lintNote: this repo builds with Go 1.20+, but CI runs on a supported Go release line for the latest security fixes.