【发布时间】:2022-01-04 20:28:54
【问题描述】:
我已经构建了自己的 Docker 容器,该容器提供了要部署为 Amazon Sagemaker 上的端点的推理代码。但是,此容器需要能够访问 s3 中的某些文件。使用的 IAM 角色可以访问我尝试访问的所有 s3 存储桶。
使用 boto3 客户端下载文件的代码:
import boto3
model_bucket = 'my-bucket'
def download_file_from_s3(s3_path, local_path):
client = boto3.client('s3')
client.download_file(model_bucket, s3_path, local_path)
IAM 角色的政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::my-bucket/*"
]
}
]
}
在本地启动 docker 容器可以让我像预期的那样从 s3 下载文件。
在 Sagemaker 上部署为端点,但是,请求超时:
botocore.vendored.requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='my-bucket.s3.eu-central-1.amazonaws.com', port=443): Max retries exceeded with url: /path/to/my-file (Caused by ConnectTimeoutError(<botocore.awsrequest.AWSHTTPSConnection object at 0x7f66244e69b0>, 'Connection to my-bucket.s3.eu-central-1.amazonaws.com timed out. (connect timeout=60)'))
感谢任何帮助!
【问题讨论】:
标签: python-3.x amazon-web-services boto3 amazon-sagemaker