AWS MFA cli script

Categories: General, Linux, Misc, OS, Script

sup everyone.

Been working and managing things so have not had too much time to do a post.

Recently though i started having to do a bunch of tasks involving AWS from the CLI and would constantly get irritated at having to copy / paste all the things for the mfa to work so instead i wrote this script here

Quick breakdown:
script is invoked by source ./aws_mfa_cli.sh

Lines 24-35 test to see whether its on mac or linux so that it can create the proper temp file and also a generic trap statement

Lines 38-47 just checks to ensure that the aws binary / system tools are installed

Lines 50-65 this function ask the user for their MFA arn and the MFA code

Lines 67-76 this function queries AWS for the access key, secret key, session token, and sets the duration

Lines 78-83 this function unsets the previous keys and token

Lines 85-93 this function sets and exports the keys and tokens

Lines 95-100 these lines just call the functions in order

once ran, you will now have Multi-Factor Authentication at the CLI for 3600 seconds (one hour).

«
»

    Leave a Reply

    Your email address will not be published. Required fields are marked *