我在 Amazon Elastic Container Service (Amazon ECS) 中從 Amazon Elastic Container Registry (Amazon ECR) 提取 Docker 映像檔時,收到「error pulling image configuration: error parsing HTTP 403 response body」錯誤。
簡短描述
Amazon ECR 使用 Amazon Simple Storage Service (Amazon S3) 儲存您的映像檔層。容器從 Amazon ECR 下載映像檔時,會先存取 Amazon ECR 以取得映像檔資訊清單,再存取 Amazon S3 以下載映像檔層。
存放各個 Docker 映像檔層的 Amazon S3 儲存貯體使用以下 Amazon Resource Name (ARN):
arn:aws:s3:::prod-region-starport-layer-bucket/*
注意: 請將 region 替換為您的 AWS 區域。
若您在路由表中使用 Amazon S3 閘道端點,且端點政策限制對 starport-layer-bucket 的存取,便會收到以下錯誤訊息:
"error pulling image configuration: error parsing HTTP 403 response body: invalid character '<' looking for beginning of value: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>SAMPLE-REQUEST-ID</RequestId><HostId>SAMPLE-HOST-ID</HostId></Error>"
根據預設,閘道端點會提供所有 Amazon S3 資源的完整存取權。
若您使用自訂政策來允許存取特定資源,請將 starport-layer-bucket 的 ARN 新增至您的 Amazon Virtual Private Cloud (Amazon VPC) 端點政策。
解決方法
若要解決此錯誤,請完成以下步驟:
- 開啟 Amazon VPC console (Amazon VPC 主控台)。
- 在導覽窗格中,選擇 Endpoints (端點)。
- 選取 Amazon S3 閘道端點。
- 選擇 Policy (政策) 索引標籤,再選擇 Edit policy (編輯政策)。
- 在政策的 Resource 區段中,新增以下 ARN:
arn:aws:s3:::prod-region-starport-layer-bucket/*
注意: 請將 region 替換為您的 AWS 區域。
VPC 端點政策範例:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Access-to-specific-buckets",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::prod-us-east-1-starport-layer-bucket/*"
]
}
]
}
相關資訊
建立 Amazon S3 閘道端點