我试图通过boto3使用S3Control创建AmazonS3批处理(不是AWS批处理,这是S3批处理操作)作业,但请求无效。我通过控制台通过AmazonS3批处理操作来完成它,我正在尝试通过boto3来创建批处理作业。附件是代码和错误消息
import boto3
from datetime import datetime
from botocore.exceptions import ClientError
client = boto3.client('s3')
client_control = boto3.client('s3control')
client_control.create_job(
AccountId='71652345619605',
ConfirmationRequired=True,
Operation={
'S3PutObjectCopy': {
'TargetResource': 'arn:aws:s3:::worm-all-bucket-inventory-embark',
'StorageClass': 'DEEP_ARCHIVE',
'ObjectLockLegalHoldStatus': 'OFF',
'ObjectLockMode': 'COMPLIANCE',
'ObjectLockRetainUntilDate': datetime(2115, 1, 1)
}
},
Report={
'Bucket': 's3-batch-ops-report',
'Enabled': True,
'ReportScope': 'AllTasks'
},
Manifest={
'Spec': {
'Format': 'S3BatchOperations_CSV_20180820',
'Fields': [
'Bucket', 'Key', 'VersionId', 'TaskStatus', 'ErrorCode', 'HTTPStatusCode', 'ResultMessage'
]
},
'Location': {
'ObjectArn': 'arn:aws:s3:::all-bucket-inventory-embark/agentwidget/2/2021-08-26T00-00Z/manifest.json',
'ETag': 'fdc154f55282ef570cc9023068a72fc2'
}
},
Priority=10,
RoleArn='arn:aws:iam::716293619605:role/s3BatchOps'
)
答复:
Traceback (most recent call last):
File "/Users/davefogo/Documents/Workspace/sprinters/AWS/AWS_CLI_Scripts/python-scripts/create_job.py", line 10, in <module>
client_control.create_job(
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidRequest) when calling the CreateJob operation: Request invalid
根据boto3的文档,字段
ObjectLockRetainUntilDate
应该是一个datetime
对象,而您的当前是一个str
对象。您可以尝试将其从'2115, 01, 01'
更改为datetime.datetime(2115, 1, 1)
相关问题 更多 >
编程相关推荐