lak*_*map 4 python amazon-s3 boto3 aws-lambda
我尝试使用 S3Control 通过 boto3 创建 S3 Batch(不是 AWS Batch,这是 S3 Batch 操作)作业,但我收到“无效请求”响应。我通过控制台通过 AWS S3 批处理操作进行了尝试,但现在我尝试通过 boto3 创建批处理作业。附件是代码和错误消息。
\nimport json\nimport boto3\nimport time\nimport datetime\nimport os\ns3ControlClient = boto3.client('s3control')\ndef lambda_handler(event, context):\n accountId = boto3.client('sts').get_caller_identity().get('Account')\n print(accountId)\n response = s3ControlClient.create_job(\n AccountId = accountId,\n ConfirmationRequired = False,\n Operation = {\n 'S3PutObjectRetention': {\n 'BypassGovernanceRetention': False,\n 'Retention': {\n 'RetainUntilDate' : datetime.datetime(2050, 06, 03),\n 'Mode' : 'GOVERNANCE'\n }\n }\n },\n Report={\n 'Bucket' : 'arn:aws:s3:::test-s3-inventory',\n 'Format' : 'Report_CSV_20180820',\n 'Enabled' : True,\n #'Prefix' : time.strftime('%Y%m%d'),\n 'Prefix' : 'report',\n 'ReportScope' : 'AllTasks'\n },\n Manifest={\n 'Spec': {\n 'Format': 'Report_CSV_20180820',\n 'Fields': [\n 'Bucket', 'Key', 'VersionId', 'TaskStatus', 'ErrorCode', 'HTTPStatusCode', 'ResultMessage'\n ]\n },\n 'Location': {\n 'ObjectArn' : 'https://test-s3-inventory.s3.amazonaws.com/job-34455-4eb5-829d-7eedrrr8564/manifest.json',\n 'ETag' : 'f4a7c0618aaed7777a5be40c266abe1f'\n }\n },\n Description = time.strftime('%Y-%m-%d')+' - Apply Retention and Legal Hold',\n Priority = 10,\n RoleArn = 'arn:aws:iam::277696433388194:role/s3BatchRole',\n Tags = [\n {'Key': LOB', 'Value': 'Test'},\n {'Key': 'project', 'Value': \xe2\x80\x98test project\xe2\x80\x99}\n ]\n )\n\nError:\n Response:\n {\n "errorMessage": "An error occurred (InvalidRequest) when calling the CreateJob operation: Request invalid",\n "errorType": "ClientError",\n "stackTrace": [\n " File \\"/var/task/lambda_function.py\\", line 13, in lambda_handler\\n response = s3ControlClient.create_job(\\n",\n " File \\"/opt/python/botocore/client.py\\", line 316, in _api_call\\n return self._make_api_call(operation_name, kwargs)\\n",\n " File \\"/opt/python/botocore/client.py\\", line 635, in _make_api_call\\n raise error_class(parsed_response, operation_name)\\n"\n ]\n }\nRun Code Online (Sandbox Code Playgroud)\n
小智 5
我认为您的代码中有两个小错误:
arn:aws:s3:::test-s3-inventory/job-34455-4eb5-829d-7eedrrr8564/manifest.json
Run Code Online (Sandbox Code Playgroud)
Report_CSV_20180820) 是错误的;相反你想要:
S3BatchOperations_CSV_20180820
Run Code Online (Sandbox Code Playgroud)