python-3.x - 由于调用者没有权限,从 S3 到 GCS 的 Google StorageTransfer 作业失败
问题描述
我尝试使用 API 将文件从 Amazon S3 传输到 Google Cloud Storage。我在 GCP 控制台上成功了,但是当我使用服务帐户凭据编写 Python 脚本时,我得到了HttpError 403 when requesting https://storagetransfer.googleapis.com/v1/transferJobs?alt=json returned "The caller does not have permission
此外,我的服务帐户已经是存储对象管理员。
我正在使用的脚本
import google.auth
import google_auth_httplib2
import google.oauth2.service_account
from googleapiclient.discovery import build
_DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',)
credentials = (
google.oauth2.service_account.Credentials.from_service_account_file(
key_path, scopes=_DEFAULT_SCOPES)
)
http = httplib2.Http()
http_authorized = google_auth_httplib2.AuthorizedHttp(
credentials, http=http)
conn = build('storagetransfer', 'v1', http=http_authorized, cache_discovery=False)
now = datetime.datetime.utcnow()
project_id='projectid'
transfer_spec = {
'awsS3DataSource': {
'bucketName': 's3_bucket',
'awsAccessKey': {
'accessKeyId': 'key',
'secretAccessKey': 'secret',
}
},
'gcsDataSink': {
'bucketName': 'bucket',
},
'objectConditions': {'includePrefixes': ['PREFIX']},
'transferOptions': {'overwriteObjectsAlreadyExistingInSink': True},
}
transfer_job = {
'status': 'ENABLED',
'projectId': project_id,
'transferSpec': transfer_spec,
'schedule': {
'scheduleStartDate': {
'day': now.day,
'month': now.month,
'year': now.year,
},
'scheduleEndDate': {
'day': now.day,
'month': now.month,
'year': now.year,
}
}
}
job = conn.transferJobs().create(body=transfer_job).execute()
有谁知道缺少什么?
文档:https ://cloud.google.com/storage-transfer/docs/reference/rest/v1/transferJobs/create
解决方案
根据此处的文档,您需要分配以下权限所有者/编辑器/storagetransfer.admin/storagetransfer.user 之一。还有一个 python 脚本示例可能有助于将数据从 S3 传输到 GCS。
推荐阅读
- elixir - 无法创建 Rumbl.Repo 的数据库:已杀死
- javascript - 到达页面顶部时如何将tr粘贴在表格中间
- c# - 无法解析类型:System.String、System.Private.CoreLib、版本 4.0.0.0 - Asp.net Core (.net core 2.1) 服务器、.NET 4.6.1 客户端
- android - 当我单击警报对话框中的 Recycler 视图项时,它显示错误:活动已泄漏窗口 DecorView@1ac0c00[] 最初添加在此处
- python - python 3.6之前有没有像__init_subclass__()这样的方法
- json - 带有 json 编码的 avro 模式 - 如何从序列化数据中确定模式
- c# - 如何在使用迁移更新数据库期间修复关键字“NOT”附近的错误语法
- c++ - 如何使用 qmake 将 pcl 库成功添加到 qt 项目中
- vba - VBA 创建具有不同行长度的 CSV
- .htaccess - 使用 htaccess 重定向带有问号的站点页面