Let's say I have set up an IAM policy to enforce multi-factor authentication (MFA) for all AWS API requests (such as the one described here: https://stackoverflow.com/a/70792832/2800876). I can get and use temporary credentials via sts get-session-token with the following code:
# Get the serial number of your MFA device
aws --profile <PROFILE_NAME> iam list-mfa-devices --user-name <IAM_USER_NAME>
# Get temporary API keys that will pass MFA verification
aws --profile <PROFILE_NAME> sts get-session-token --serial-number <MFA_SERIAL_NUMBER> --token-code <MFA_TOKEN>
# Export the temporary credentials for use in subsequent calls
export AWS_ACCESS_KEY_ID=<KEY>
export AWS_SECRET_ACCESS_KEY=<SECRET>
export AWS_SESSION_TOKEN=<SESSION_TOKEN>
However, this code requires several steps and only works for the terminal window I do it in. How do I make this work with a single command that saves the credentials until they expire?