mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Use Specific AWS Profile With CLI as an AWS TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1597 TILs and counting..._
|
||||
_1598 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||
@@ -111,6 +111,7 @@ See some of the other learning resources I work on:
|
||||
- [AWS CLI Requires Groff Executable](aws/aws-cli-requires-groff-executable.md)
|
||||
- [Find And Follow Server Logs](aws/find-and-follow-server-logs.md)
|
||||
- [Sign Up User With Email And Password](aws/sign-up-user-with-email-and-password.md)
|
||||
- [Use Specific AWS Profile With CLI](aws/use-specific-aws-profile-with-cli.md)
|
||||
|
||||
### Brew
|
||||
|
||||
|
||||
37
aws/use-specific-aws-profile-with-cli.md
Normal file
37
aws/use-specific-aws-profile-with-cli.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Use Specific AWS Profile With CLI
|
||||
|
||||
I have multiple AWS profiles authenticated with the AWS CLI. For some projects
|
||||
I need to use the `default` one and for others I need to use the other.
|
||||
|
||||
First, I can list the available profiles like so:
|
||||
|
||||
```bash
|
||||
$ aws configure list-profiles
|
||||
default
|
||||
dev-my-app
|
||||
```
|
||||
|
||||
For one-off commands I can specify the profile for any AWS CLI command using
|
||||
the `--profile` flag.
|
||||
|
||||
```bash
|
||||
$ aws ecs list-clusters --profile josh-visualmode
|
||||
```
|
||||
|
||||
However, I don't want to have to specify that flag every time when I'm working
|
||||
on a specific project. Instead I can specify the profile with an environment
|
||||
variable. The [`direnv`](https://direnv.net/) tool is a great way to do this on
|
||||
a per-project / per-directory basis.
|
||||
|
||||
I can create or update the `.envrc` file (assuming I have `direnv` installed)
|
||||
adding the following line (and re-allowing the changed file):
|
||||
|
||||
```
|
||||
# .envrc
|
||||
export AWS_PROFILE=dev-my-app
|
||||
```
|
||||
|
||||
Now, any AWS command I issue from that directory or its subdirectories will use
|
||||
that profile by default.
|
||||
|
||||
[source](https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html#cli-configure-files-using-profiles)
|
||||
Reference in New Issue
Block a user