Skip to content

Instantly share code, notes, and snippets.

@namndev
Last active March 6, 2020 04:12
Show Gist options
  • Save namndev/4b43d9318144a2921acbafedf7e8f406 to your computer and use it in GitHub Desktop.
Save namndev/4b43d9318144a2921acbafedf7e8f406 to your computer and use it in GitHub Desktop.
Guide Install AWS-CLI

I. Install AWS-CLI in Centos7

There are a number of ways to install the AWS command line tools. Below is the method I favour on CentOS:

$curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$unzip awscli-bundle.zip
$cd awscli-bundle/
$sudo ./install -i /usr/local/aws -b /usr/local/bin/aws

Check that was successful with:

$aws --version
aws-cli/1.16.256 Python/2.7.5 Linux/3.10.0-957.12.2.el7.x86_64 botocore/1.12.246

You can now remove the files extracted:

$rm -vR ~/awscli-bundle/
$rm -v ~/awscli-bundle.zip

Configure aws-cli to use your AWS credentials:

$aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: eu-west-1
Default output format [None]: json

You can test your AWS credentials with the below command.

$aws sts get-caller-identity
{
    "Account": "903503371367", 
    "UserId": "AKIAIOSFODNN7EXAMPLE", 
    "Arn": "arn:aws:iam::903503371367:user/andy"
}

II. Install AWS-CLI in MacOS

aws-cli yêu cầu máy bạn phải cài đặt phiên bản Python tối thiểu là 2.6.5.

Có thể kiểm tra phiên bản python đang sử dụng trên máy bằng lệnh:

$python --version

1.Cài đặt bằng Bundle Installer

Tải bộ cài aws-cli:

$curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

Giải nén bộ cài đặt:

$unzip awscli-bundle.zip

Cài đặt:

$sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

2. Cài đặt bằng pip

Cài đặt bằng lệnh:

$pip3 install awscli --upgrade --user

Kiểm tra lại xem đã cài đặt được chưa bằng lệnh:

$aws --version

Để cập nhật phiên bản mới của aws-cli có thể dùng lệnh:

$pip3 install awscli --upgrade --user

Sau khi cài đặt aws-cli, bạn cần thêm cấu hình vào trong biến môi trường của hệ điều hành như sau:

Kiểm tra thư mục cài đặt của python trên máy:

$which python

Giả sử thư mục cài đặt là ~/Library/Python/3.7/bin, ta cần thêm dòng sau vào profile script:

export PATH=~/.local/bin:$PATH 

Tải lại file profile bằng lệnh:

$source ~/.bash_profile

3. Cấu hình cho aws-cli

Chạy lệnh sau:

$aws configure

Người dùng sẽ cần nhập các thông tin sau trong màn hình hiện ra:

AWS Access Key ID [None]:
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]: json

Người dùng có thể lấy các thông tin trên bằng cách:

  • Đăng nhập vào console.aws.amazon.com
  • Truy cập vào chức năng IAM console.
  • Chọn Users.
  • Chọn User cần sử dụng.
  • Trong màn hình hiện ra, chọn tab Security credentials và chọn Create access key.
  • Trong màn hình tạo, chọn show để lấy thông tin.

III. Some commands

AWS S3API

Create bucket

aws s3api create-bucket --bucket namnd-test --region ap-southeast-1 --create-bucket-configuration LocationConstraint=ap-southeast-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment