問題
將Delta Lake格式的DataFrame內容寫入S3位置會導致錯誤:
com.amazonaws.services.s3.model。亞馬遜S3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: C827672D85516BA9; S3 Extended Request ID:
導致
一個寫涉及Delta Lake格式的操作需要其他文件格式不需要的權限。例如,Delta Lake需要創建一個_delta_log目錄中。的寫操作還需要檢查最新版本的提交日誌。需要為IAM和桶角色添加額外的權限,才能使寫操作成功完成。
解決方案
添加以下權限以啟用Delta表的寫入:
- 將這些權限添加到IAM policy JSON中:
["s3:PutObject","s3:DeleteObject", "s3:ListBucket", "s3:GetObject", "s3: PutObjectAcl"]
- 將這些權限添加到桶策略JSON中:
[" s3: GetObject”、“s3: GetObjectVersion”、“s3: propertynames”,“s3: DeleteObject”、“s3: ListBucket”,“s3: GetBucketLocation”)
或者,您也可以使用JSON格式的IAM策略添加權限,如下所示:
{"版本":"2012-10-17","聲明":[{"Sid": "VisualEditor0", "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::: mybucket "}, {"Sid": "VisualEditor1", "Effect": "Allow", "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject", "s3:PutObjectAcl"], "Resource": "arn:aws:s3:::: mybucket /subfolder/*"}]}