Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

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?

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

1 Answer

0 votes
by (44.4k points)

You can use these following command-options using EC2_PRIVATE_KEY (and even EC2_CERT) environment variables:

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

After that, you can use them inside aliases, e.g.

alias ec2-describe-instances1 ec2-describe-instances -K /path/to/yourkey.pem

There is also a straightforward way to do this:

$ aws configure --profile myaccount1

$ aws configure --profile myaccount2

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

$ aws dynamodb list-tables --profile myaccount1

$ aws s3 ls --profile myaccount2

Also, you can set your primary account by mentioning default in it

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories