# aws-creds-generator-multi

This is a fork of the [aws-creds-generator](https://github.com/theorchard/collab/tree/master/jcarrion/aws-creds-generator) by **jcarrion**, et. al. This version allows users to maintain multiple profiles in their AWS credentials file.

## Reasoning
The existing temp credential generation script backs up the existing credentials file, and then summarily overwrites it with a new `default` profile containing the new temp creds.

This version of the script will honor existing profiles, and simply add a `temp` profile for your new AWS credentials.

All effective behaviours of the prevailing script are maintained. This version merely changes how the temp creds are stored in the `~/.aws/credentials` file.

## Basic Usage
Example use of this script:
```
. ./generate_temp_profile.sh
```

You may supply an optional param for the profile name, rather than providing it interactively:
```
. ./generate_temp_profile.sh dev
```

You may also supply an optional second param for the one-time auth token, rather than providing it interactively, e.g.:
```
. ./generate_temp_profile.sh dev 123987
```

In order to use the new credentials, simply preface your `aws` commands with `AWS_DEFAULT_PROFILE=(temp profile name)`.
```
# Run aws s3 ls using temp credentials
$ AWS_DEFAULT_PROFILE=temp aws s3 ls s3://bucket_name
```

If you choose to employ a prefix and/or suffix, you will have to add them appropriately when referencing the temp credentials you have created. 

## Extended Usage

### Profile Prefixes
If a user merely has `dev` and `prod` accounts in their `~/.aws/credentials` file, there is no need to edit the script.

If, however, a prefix or suffix to the default `dev`/`prod` profile names are preferred, these can be specified by editing the appropriate section of the script:

    # AWS credential file profile name prefix / suffix
    # e.g. profile_prefix=orch_
    profile_prefix=
    profile_suffix=

***N.B. If you have NOT previously used prefixes or suffixes and decide to employ them now, and you have run the prevailing temp credential genereator script, you should backup, rename, and/or remove the existing `~/.aws/.store` file.***
### Bash Aliases
You may also create a bash alias for your new credentials. (Or your existing creds as desired.)

    alias orchtempaws='AWS_DEFAULT_PROFILE=temp aws'
    # alias orchprodaws='AWS_DEFAULT_PROFILE=prod aws'
    # alias orchdevaws='AWS_DEFAULT_PROFILE=dev aws'

Which will allow the execution of `AWS CLI` commands using these new credentials more simply, as such:

    $ orchtempaws s3 ls s3://bucket_name
