網頁

2023/5/10

AWS CLI 透過S3 bucket access point上傳檔案

使用AWS CLI透過S3 bucket的access pointt上傳檔案。


範例環境:

  • macOS
  • AWS CLI version 2 (aws-cli/2.9.19)


例如bucket有一名稱為my-access-point的access point的alias(別名)my-access-point-imskxg855p49i8ukqyrpatkdeq4fnuse1a-s3alias

在命令列輸入AWS CLI命令aws s3api put-object --bucket my-access-point-imskxg855p49i8ukqyrpatkdeq4fnuse1a-s3alias --key hi.txt --body hi.txt --region us-east-1把所在目錄中的hi.txt上傳到bucket為hi.txt

若AWS CLI的region不同於bucket的region,則後面必須加上--region <BUCKET_REGION>用來指名bucket所在region,例如上面的--region us-east-1,否則會出現錯誤An error occurred (IllegalLocationConstraintException) when calling the PutObject operation: The <BUCKET_REGION> location constraint is incompatible for the region specific endpoint this request was sent to.

~/Documents% aws s3api put-object --bucket my-access-point-imskxg855p49i8ukqyrpatkdeq4fnuse1a-s3alias --key hi.txt --body hi.txt --region us-east-1
{
    "ETag": "\"49f68a5c8493ec2c0bf489821c21fc3b\"",
    "ServerSideEncryption": "AES256"
}

執行後在AWS console的S3 bucket可看到上傳的hi.txt


沒有留言:

張貼留言