Aws Command Line Tool For Mac

Active1 year, 8 months ago

With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts. In this blog, I will show you how to use AWS CLi and how to install it on your Windows, Linux, Mac, or Unix Operating System.

I've got two different apps that I am hosting (well the second one is about to go up) on Amazon EC2.

How can I work with both accounts at the command line (Mac OS X) but keep the EC2 keys & certificates separate? Do I need to change my environment variables before each ec2-* command?

Aws Command Line Tool For Mac

Would using an alias and having it to the setting of the environment in-line work? Something like:

alias ec2-describe-instances1 = export EC2_PRIVATE_KEY=/path ; ec2-describe-instances

Spencer Ruport
31.5k11 gold badges77 silver badges130 bronze badges
Matt CulbrethMatt Culbreth
8001 gold badge8 silver badges17 bronze badges

6 Answers

You should be able to use the following command-options in lieu of the EC2_PRIVATE_KEY (and even EC2_CERT) environment variables:

  • -K <private key>
  • -C <certificate>

You can put these inside aliases, e.g.

slm
9,47710 gold badges68 silver badges85 bronze badges
vladrvladr
57k14 gold badges117 silver badges122 bronze badges

You can work with two accounts by creating two profiles on the aws command line.It will prompt you for your AWS Access Key ID, AWS Secret Access Key and desired region, so have them ready.

Examples:

You can then switch between the accounts by passing the profile on the command.

Note:

If you name the profile to be default it will become default profile i.e. when no --profile param in the command.

More on default profile

If you spend more time using account1, you can make it the default by setting the AWS_DEFAULT_PROFILE environment variable. When the default environment variable is set, you do not need to specify the profile on each command.

Linux, OS X Example:

Windows Example:

slm
9,47710 gold badges68 silver badges85 bronze badges
Aws Command Line Tool For MaciBrianCoxiBrianCox
2,3212 gold badges5 silver badges3 bronze badges

Maybe it still help someone. You can set it manually.

1) Set in file

this

  • {{aws_access_key_id}} you can get in section AWS Console > Identity and Access Management > Security Credentials > Access Keys

2) Set in file

this

3) Test it with AWS Command Line and command and output will be JSON

Ref

BG BrunoBG BrunoAws Command Line Tool For Mac
3,2263 gold badges32 silver badges43 bronze badges

The new aws tools now support multiple profiles.

If you configure access with the tools, it automatically creates a default in ~/.aws/config.

You can then add additional profiles - more details at:

chrischris

Aws Command Line Tools Macos

22.3k46 gold badges140 silver badges224 bronze badges

You can write shell script to set corresponding values of environment variables for each account based on user input. Doing so, you don't need to create any aliases and, furthermore, tools like ELB tools, Auto Scaling Command Line Tools will work under multiple accounts as well.

Roman NewazaRoman Newaza
7,9319 gold badges42 silver badges69 bronze badges

I recommend checking out docker container encapsulated CLI. you can run container for every account for better isolation.

Wassim SeifeddineWassim Seifeddine

Aws Cli For Windows

Not the answer you're looking for? Browse other questions tagged amazon-ec2amazon-web-services or ask your own question.