AWS CLI 설치하기

AWS S3에 8GB 정도의 파일을 업로드 할 일이 생겨서 찾다보니 다른 방법 보다 AWS CLI의 sync 명령을 사용하는 것이 좋다는 판단에 AWS CLI 를 설치해서 사용해 보기로 했다.

OS별 설치 방법

Amazon Linux를 설치하면 기본적으로 AWS CLI가 설치되어 있다.

  • Windows

    64비트 또는 32비트 Windows 설치 프로그램을 다운로드해서 실행한다.

  • Mac or Linux

    Python 2.6.5 이상이 필요하고 pip를 사용하여 설치한다.

    난 그냥 brew를 이용해서 설치했다.

    1
    $ brew install awscli

기본 설정

aws configure 명령을 통해서 기본 액세스키, 시크릿키, 리전을 설정한다.

  • AWS Access Key ID [None]: 액세스 키를 입력한다.
  • AWS Secret Access Key [None]: 시크릿 키를 입력한다.
  • Default Region name [None]: Seoul 리전을 뜻하는 ap-northeast-2를 입력한다.
  • Default output format [None]: 비워둔다.(json, text, table을 사용할 수 있다.)
    1
    2
    3
    4
    5
    $ aws configure
    AWS Access Key ID [None]:
    AWS Secret Access Key [None]:
    Default region name [None]: ap-northeast-1
    Default output format [None]:

기본 사용법

우리는 S3에 파일을 업로드 해야 하기 때문에 관련 사용 방법은 http://docs.aws.amazon.com/cli/latest/reference/s3/를 참고.

aws s3 sync 명령을 통해 파일을 업로드 하는 방법

  • aws s3 sync 명령 사용방법은 http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html를 참고
  • 기본 명령 형식은 아래와 같다.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    $ aws s3 sync ./ s3://mybucket
    upload: test.txt to s3://mybucket/test.txt
    upload: test2.txt to s3://mybucket/test2.txt
    or
    $ aws s3 sync s3://mybucket ./
    download: s3://mybucket/test.txt to test.txt
    download: s3://mybucket/test2.txt to test2.txt
    or
    $ aws s3 sync s3://mybucket s3://mybucket2
    copy: s3://mybucket/test.txt to s3://mybucket2/test.txt
    copy: s3://mybucket/test2.txt to s3://mybucket2/test2.txt

위 방법을 사용하여 아래와 같이 파일을 업로드 했다.

1
$ aws s3 sync Download/images s3://freegians/images

결과는 실패

아시아 태평양(뭄바이), 아시아 태평양(서울), EU(프랑크푸르트) 및 중국(베이징) 리전에서 Amazon S3는 signature version 4만 지원하고 나머지 모든 리전에서는 Amazon S3에서 signature version 4와 2를 모두 지원한다고 한다.
설치된 AWS CLI sdk signature version이 2 였던 것이다.

아래 명령을 통해 signature version 4로 변경해보자.

1
$ aws configure set default.s3.signature_version s3v4

다시 aws s3 sync 명령 실행하니 성공