/aws_utilities

A small collection of AWS utilities

Primary LanguageShell

README

What is this repository for?

This is a repository to collect various utilities/scripts etc that may not be big enough to warrant their own repositories and does not belong to a specific project or solution.

Utilities

aws_aliases

A bash script that provides some conveniance aliases for command line to switch and list between AWS profiles. It assumes that the AWS CLI is installed, as well as that python 2.x is available, if MFA support is to be used.

  • Clone the repository.
  • In your $HOME/.bashrc, add an entry . /aws_aliases
  • When a new command line window (with bash) is opened, three commands will be available:
  • awsall - List all available profiles
  • awswho - Show info about current profile
  • awsp profile - Switch to profile profile.
  • awsenv [profile] - set environment variables with data from profile

If the profile entry in $HOME/.aws/credentials has a config entry

mfa_serial=arn:aws:iam::123456789012:mfa/user_account_name

then it is assumed that switching to that profile will require MFA and it will ask for an MFA token from the MFA device configured. The value to set is the serial id for the MFA device. This can be found in the IAM user account information, under tab "Security credentials", field "Assigned MFA device". The ARN is used if the MFA device is a virtual device, hardware MFA devices uses a different format. The session token when authenticated with MFA will be valid for 12 hours, or until the profile is changed or the cache is cleared; whichever comes first. If a profile entry has role_arn entry set, then it will try to execute assume-role on that role, using the current active/default profile as source profile. For setups that require environment variables to be set with credentials, the alias awsenv can be used to set the environment variables based on the profile configuration specified. If no profile is specified, then awsenv unsets the corresponding environment variables. The variables affected are:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN
  • AWS_REGION

If awsp has been used to switch to a specific profile, then executing

prompt>awsenv default

will set the environment variables to that same target profile.