我需要將_bucket_analytics_configuration 放到特定的 s3 存盤桶中。命名為“測驗桶”。我寫了一個python代碼:
import boto3
client = boto3.client('s3')
response = client.put_bucket_analytics_configuration(
Bucket='test-bucket',
Id='storage-class-analysis',
AnalyticsConfiguration={
'Id':'storage-class-analysis',
'Filter': {
'Prefix' : 'dir',
'Tag': {
'Key':'production',
'Value':'true'
}
},
'StorageClassAnalysis' : {
'DataExport' : {
'OutputSchemaVersion':'V_1',
'Destination' : {
'S3BucketDestination': {
'Format' : 'CSV',
'BucketAccountId': '************',
'Bucket' : 'arn:aws:s3:::storage-class-analysis-bucket-logs',
'Prefix' : 'dir'
}
}
}
}
},
ExpectedBucketOwner='************'
)
但我得到了這個錯誤:
Traceback (most recent call last):
File "C:\Python learning\Natalia\test.py", line 5, in <module>
response = client.put_bucket_analytics_configuration(
File "C:\Users\Ant\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 401, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\Ant\AppData\Local\Programs\Python\Python39\lib\site-packages\botocore\client.py", line 731, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the PutBucketAnalyticsConfiguration operation: The XML you provided was not well-formed or did not validate against our published schema
所以我從“get_bucket_analytics_configuration”輸出中復制了配置:
"AnalyticsConfiguration":{
"Id":"string",
"Filter":{
"And":{
"Prefix":"dir",
"Tags":[
{
"Key":"production",
"Value":"true"
}
]
}
},
"StorageClassAnalysis":{
"DataExport":{
"OutputSchemaVersion":"V_1",
"Destination":{
"S3BucketDestination":{
"Format":"CSV",
"Bucket":"arn:aws:s3:::storage-class-analysis-bucket-logs",
"Prefix":"dir"
}
}
}
}
}
}
你能告訴我為什么我會收到這樣的錯誤。我到底需要在這里修復什么?
uj5u.com熱心網友回復:
這段代碼對我有用:
import boto3
client = boto3.client('s3')
response = client.put_bucket_analytics_configuration(
Bucket='test-bucket211',
Id='storage-class-analysis',
AnalyticsConfiguration={
'Id':'storage-class-analysis',
'Filter': {
'And': {
'Prefix' : 'dir',
'Tags':[ {
'Key':'production',
'Value':'true'
} ]
}
},
'StorageClassAnalysis' : {
'DataExport' : {
'OutputSchemaVersion':'V_1',
'Destination' : {
'S3BucketDestination': {
'Format' : 'CSV',
'BucketAccountId': '****',
'Bucket' : 'arn:aws:s3:::destination_bucket',
'Prefix' : 'dir'
}
}
}
}
},
ExpectedBucketOwner='*****'
)
略有不同的是,我在Filter屬性中使用And并將Tags 設為陣列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/463945.html
標籤:Python 亚马逊网络服务 亚马逊-s3 博托3 aws-cdk
