通过boto3请求的Amazon S3批处理作业无效

2024-04-19 11:32:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过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

Tags: pyimportclientawsdatetimes3createjob
1条回答
网友
1楼 · 发布于 2024-04-19 11:32:35

根据boto3的文档,字段ObjectLockRetainUntilDate应该是一个datetime对象,而您的当前是一个str对象。您可以尝试将其从'2115, 01, 01'更改为datetime.datetime(2115, 1, 1)

相关问题 更多 >