1. 程式人生 > 其它 >通過 AWS CLI 操作 AWS S3

通過 AWS CLI 操作 AWS S3

AWS S3後臺提供了上傳檔案的地方,但是大檔案上傳比較慢--- 幾十kb/s。使用AWS CLI上傳檔案相對較快

1:安裝CLI (這裡環境是 Windows)

參考官方文件 :https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html

2:獲取Access Key:

在AWS後臺選擇IAM中,點選使用者->選擇一個擁有S3許可權的使用者。

我這個使用者擁有操作s3的許可權

建立一個密碼,並下載下來

3:配置CLI

$ aws configure --profile produser
AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF
/2Zp9Utk/h3yCo8nvbEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: text

注意:之前使用 aws configure 設定時後,使用時儲存:

The AWS Access Key Id you provided does not exist in our records.

所以使用了 aws configure --profile produser。如果你沒有報錯,可以不攜帶後面的指定配置檔案

測試一下:注意後面使用時需要帶上認證 --profile produser

aws s3 ls --profile produser

4:上傳檔案:將本地資料夾 /d/homes 資料夾下所有檔案上傳到 桶 buoss的test資料夾目錄下

cd 到本地資料夾內, cd /d/homes

命名上傳檔案到指定路徑下

aws s3 sync . s3://buoss/test --profile produser

//aws  s3 sync   .(當前資料夾所有檔案) s3...(上傳的伺服器地址)

檢視AWS s3儲存桶:

參考:https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html