{"id":12113,"date":"2014-02-27T15:10:54","date_gmt":"2014-02-27T09:40:54","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=12113"},"modified":"2014-12-17T09:06:19","modified_gmt":"2014-12-17T03:36:19","slug":"using-multiple-iam-accounts-through-aws-cli-tool","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-multiple-iam-accounts-through-aws-cli-tool\/","title":{"rendered":"Using multiple IAM Accounts through AWS CLI tool"},"content":{"rendered":"<p>AWS CLI tool allows you to switch between multiple IAM accounts. This becomes very handy while you are writing a script that involves multiple IAM user accounts.<\/p>\n<p>Prerequisites :<\/p>\n<p>AWS CLI tool<\/p>\n<p>Configuring Multiple Accounts:<\/p>\n<p>When you configure your AWS CLI tool, a configuration file gets created at ~\/.aws\/config in Linux\/Unix or at <code>C:\\Users\\USERNAME\\.aws\\config <\/code>, which looks like:<\/p>\n<p>[code]<br \/>\n[default]<br \/>\naws_access_key_id=AKIAIOSFODNN7EXAMPLE<br \/>\naws_secret_access_key=wJalrXUtnFEMI\/K7MDENG\/bPxRfiCYEXAMPLEKEY<br \/>\naws_security_token=texample123324<br \/>\n[\/code]<\/p>\n<p>This has a default profile , that gets created when you run \u201c aws configure \u201c<\/p>\n<p>Now to create multiple profiles , append the following to your aws configuration file ( ~\/.aws\/config ) :<\/p>\n<p>[code]<br \/>\n[profile test-user]<br \/>\naws_access_key_id=AKIAI44QH8DHBEXAMPLE<br \/>\naws_secret_access_key=je7MtGbClwBF\/2Zp9Utk\/h3yCo8nvbEXAMPLEKEY<br \/>\nregion=us-west-2<br \/>\n[\/code]<\/p>\n<p>Note that you need to append the string \u201cprofile\u201c before the profile name .<\/p>\n<p>Now , whenever you want to use this user , you have to invoke the AWS command with the <code style=\"font-style: inherit\">--profile<\/code>\u00a0command line parameter or else you can set the environment variable AWS_DEFAULT_PROFILE . If this variable does not specify a profile, the AWS CLI uses the profile named <code style=\"font-style: inherit\">default<\/code>.<\/p>\n<p><span style=\"font-family: Liberation Serif,serif\"><span style=\"font-size: medium\"><span style=\"color: #000000\">Example: <\/span><\/span><\/span><\/p>\n<p>[code]aws s3 ls \u2013profile test-user<br \/>\naws s3 ls \u2013profile default[\/code]<\/p>\n<p><strong>Miscellaneous Tips<\/strong><\/p>\n<p>Auto Completion :<br \/>\nTo enable auto completion for you AWS CLI , add the below line in your \/etc\/bashrc file :<\/p>\n<p>[shell]complete -C aws_completer aws[\/shell]<\/p>\n<p>Configuring the command output :<br \/>\nBy default the output of the AWS CLI is json, but it also supports other formats like table and text. To change the default output you can either<\/p>\n<ul>\n<li>Configure the default format in config file :<\/li>\n<\/ul>\n<p>[shell][default]<br \/>\noutput = text[\/shell]<\/p>\n<ul>\n<li>Use the &#8211;output option with the AWS CLI command<\/li>\n<\/ul>\n<p>[shell]aws ec2 describe-instances &#8211;output table[\/shell]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AWS CLI tool allows you to switch between multiple IAM accounts. This becomes very handy while you are writing a script that involves multiple IAM user accounts. Prerequisites : AWS CLI tool Configuring Multiple Accounts: When you configure your AWS CLI tool, a configuration file gets created at ~\/.aws\/config in Linux\/Unix or at C:\\Users\\USERNAME\\.aws\\config , [&hellip;]<\/p>\n","protected":false},"author":108,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":6},"categories":[1174],"tags":[248,1342],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12113"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/108"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=12113"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12113\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=12113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=12113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=12113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}