AWS - S3 cli

우야·2021년 8월 19일
0

AWS S3를 Object Storage로 사용할때, Cli 사용에 대한 방법

  1. 환경

    • Linux(Ubuntu)
    • Object Storage Url : http://xxx.xxx.xxx.xxx:8080
    • test-bucket이 생성되어 있음
    • access-key, secret-key, region 값이 있음
  2. 설치 방법

  3. install

$ sudo ./install
[sudo] password for woo:

Running cmd: /usr/bin/python virtualenv.py --no-download --python /usr/bin/python /home/woo/.local/lib
Running cmd: /home/woo/.local/lib/aws/bin/pip install --no-binary :all: --no-cache-dir --no-index --fi://. setuptools_scm-3.3.3.tar.gz
Running cmd: /home/woo/.local/lib/aws/bin/pip install --no-binary :all: --no-cache-dir --no-index --fi://. wheel-0.33.6.tar.gz
Running cmd: /home/woo/.local/lib/aws/bin/pip install --no-binary :all: --no-build-isolation --no-cachdex  --find-links file:///home/woo/storage/awscli-bundle/packages awscli-1.20.24.tar.gz
You can now run: /home/woo/.local/lib/aws/bin/aws --version

Note: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for genemore information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/clguide/install-cliv2.html
  1. AWS 실행파일을 /user/local/bin에 복사
    • $ sudo cp /home/woo/.local/lib/aws/bin/aws /usr/local/bin/
  2. version 확인
    • $ aws --version
      aws-cli/1.20.24 Python/3.6.9 Linux/5.4.0-80-generic botocore/1.21.24
  1. Configuration 설정
$ aws configure --profile woo
AWS Access Key ID [None]: -- access key -- 
AWS Secret Access Key [None]: -- secret key --
Default region name [None]: -- region name --
Default output format [None]: json
 
 
-- 확인 --
 
$ cat .aws/config
[profile woo]
region = -- region name --
output = json
$ cat .aws/credentials
[woo]
aws_access_key_id = -- access key -- 
aws_secret_access_key = -- secret key --
  1. AWS S3 Cli Test
## Get Bucket List
 
$ aws s3api --endpoint=http://xxx.xxx.xxx.xxx:8080 list-buckets --profile woo
{
    "Buckets": [
        {
            "Name": "test-bucket",
            "CreationDate": "1970-01-01T00:00:00Z"
        }
    ],
    "Owner": {
        "DisplayName": "s3obj",
        "ID": "1101"
    }
}


###  Upload Object
 
$ aws s3api --endpoint=http://xxx.xxx.xxx.xxx:8080 put-object --profile woo --bucket test-bucket --key "cifar10-2.tar" --body "cifar10-2.tar"
{
    "ETag": "\"e74c4ade88ab2727f0eb073892f5b21c\""
}


###  Download Object
 
$ aws s3api --endpoint=http://xxx.xxx.xxx.xxx:8080 get-object --profile woo --bucket test-bucket --key "cifar10-2.tar" /home/woo/cifar10-2.tar
{
    "LastModified": "Tue, 17 Aug 2021 00:53:07 GMT",
    "ContentLength": 10240,
    "ETag": "\"e74c4ade88ab2727f0eb073892f5b21c\"",
    "VersionId": "null",
    "ContentType": "application/octet-stream",
    "Metadata": {
        "sha256": "7b2e9eb7963aa11c6462fe74617d5ebbad45f2163ac0fba073c01971f3ba5bf1",
        "s3b-last-modified": "20210610T020018Z"
    }
}
 
 
## Get Object list

$ aws s3api --endpoint=http://xxx.xxx.xxx.xxx:8080 list-objects --profile woo  --bucket test-bucket
{
    "Contents": [
        {
            "Key": "cifar10-2.tar",
            "LastModified": "2021-08-19T08:30:42Z",
            "ETag": "\"e74c4ade88ab2727f0eb073892f5b21c\"",
            "Size": 10240,
            "StorageClass": "STANDARD",
            "Owner": {
                "DisplayName": "s3obj",
                "ID": "1101"
            }
        }
    ]
}

  1. Window에서 UI로 접속 확인
profile
Fullstack developer

0개의 댓글