Skip to content

Instantly share code, notes, and snippets.

@msoe
Created February 15, 2019 10:46
Show Gist options
  • Save msoe/d16733a1151cc8aba5f5ae03e7a19148 to your computer and use it in GitHub Desktop.
Save msoe/d16733a1151cc8aba5f5ae03e7a19148 to your computer and use it in GitHub Desktop.
Installing AWS Command Line Interface on macOS

AWS CLI Using pip

$ pip3 install awscli

Check the installation

$ aws --version

Getting Access Key and Secret Access Key

  • Open IAM console
  • Users > (choose your IAM username)
  • Security credentials > Create access key
  • Choose Show
  • Take note of the Access key ID and Secret access key

Configure awscli

$ aws configure
AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxx
Default region name [None]: ap-southeast-1
Default output format [None]: text

Test the settings

$ aws s3 ls

Configure awscli for another user

$ aws configure --profile user1
// Enter new credentials
$ aws s3 ls --profile user1

Configuration and Credential Files

$ ls ~/.aws

Using Profiles with AWS CLI

$ aws ec2 describe-instances --profile user1
(OR)
$ export AWS_DEFAULT_PROFILE=user1
$ aws ec2 describe-instances

Overwriting named profiles

$ export AWS_ACCESS_KEY_ID=ASDMDIWEDFSDFWDFSDFXXX
$ export AWS_SECRET_ACCESS_KEY=zxcwerWERsdfs/asdfaDFAEKkjlkjHGo
$ export AWS_DEFAULT_REGION=us-west-2
$ export AWS_DEFAULT_OUTPUT=json
$ aws s3 ls

Command Completion

$ which aws_completer
// For bash
$ complete -C `which aws_completer` aws
// For zsh
$ source `which aws_zsh_completer.sh`

Test

$ aws lightsail get-instances --output table
$ aws lightsail download-default-key-pair

$ aws ec2 create-key-pair --key-name my-key-pair

$ aws ec2 delete-key-pair --key-name=-mykey


$ dd if=/dev/urandom bs=1 count=32 > sse.key
32+0 records in
32+0 records out
32 bytes (32 B) copied, 0.000164441 s, 195 kB/s
$ aws s3api put-object --bucket my-bucket --key test.txt --body test.txt --sse-customer-key fileb://sse.key --sse-customer-algorithm AES256
{
    "SSECustomerKeyMD5": "iVg8oWa8sy714+FjtesrJg==",
    "SSECustomerAlgorithm": "AES256",
    "ETag": "\"a6118e84b76cf98bf04bbe14b6045c6c\""
}

Generating the CLI Skeleton

$ aws ec2 run-instances --generate-cli-skeleton

$ aws ec2 run-instances --generate-cli-skeleton > ec2runinst.json

$ aws ec2 run-instances --cli-input-json file://ec2runinst.json
(Make sure "DryRun" option is false, if you get errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment