Install the AWS CLI on your Mac with Homebrew.
brew update
$ brew update $ brew search aws ==> Searching local taps... aws-apigateway-importer aws-elasticbeanstalk aws-sns-cli aws-as aws-keychain awscli aws-cfn-tools aws-mon awslogs aws-cloudsearch aws-sdk-cpp kube-aws aws-elasticache aws-shell yaws
CLI installation
$ brew install awscli Verification $ aws --version aws-cli/1.14.30 Python/3.6.4 Darwin/16.7.0 botocore/1.8.34
Setting environment variables
$ vi ~ / .bash_profile Add the following export PATH=~/.local/bin:$PATH
Access key settings
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE (your) AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY (自分の) Default region name [None]: ap-northeast-1 (Tokyo region) Default output format [None]: json (JSON if empty)
Roll switching
Profile settings
Describe the role information in the configuration file (~ / .aws / config).
[profile profile name] output = json region = ap-northeast-1 role_arn = arn: aws: iam :: Operation target AWS account ID: role / role name source_profile = default
$ vi ~ / .aws / config [profile high] role_arn = arn:aws:iam::069581120308:role/role-name region = ap-northeast-1 source_profile = default
Operation check
$ aws ec2 describe-instances --profile hoge The running instance is displayed
Default profile settings
If you don’t want to specify the profile many times,
$ export AWS_PROFILE=hoge
If so, the profile will be fixed until the end of the shell session.