In this edition, we tackle a familiar obstacle - the daily drill of authenticating against AWS with an account set up with MFA. The process can be a drag, especially if you're retrieving custom packages from your CodeArtifact repository or images from your ECR.
The Challenge:
You've probably been there - having to generate a temporary access ID and key, then manually entering these values into your .aws/credentials profile. This can become a monotonous task. Being an advocate of automation, I decided it was time to find a better way.
The Solution:
While it might not be ground-breaking, it's a time-saver and simplifies the process. I've developed custom scripts that finish the job in a flash. The star function is aws-mfa
. It initiates the AWS MFA login process from the console. All it needs is your active MFA code, which covers the rest. It updates your default profile, granting you access to your private repositories.
Behind the curtain, aws-mfa
employs your main AWS profile, secures a new session token with your MFA code, and updates your AWS credentials file with this token. It all happens smoothly and safely, whether it's updating existing profiles or creating new ones as necessary, without touching your other profiles.
Getting Started:
All you need to do is clone the repository, make sure your AWS and GitBash are current, and add the utility's location to your PATH in your .bashrc
or .zshrc
. For more information and detailed instructions, the README file in the repository has you covered.
If the daily grind of AWS authentication has you down, I encourage you to try this out. Any opportunity to make our lives as developers easier is always a win.
And remember, learning never stops. If you've discovered a more efficient way to handle this process, I'd love to hear about it!
Check out the GitHub repo right here.