我需要 put_bucket_analytics_configuration
I need to put_bucket_analytics_configuration
我需要 put_bucket_analytics_configuration 到 ex 的特定 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"
}
}
}
}
}
}
你能告诉我为什么会出现这样的错误吗?
我到底需要在这里修复什么?
这段代码对我有用:
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 成为数组。
我需要 put_bucket_analytics_configuration 到 ex 的特定 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"
}
}
}
}
}
}
你能告诉我为什么会出现这样的错误吗? 我到底需要在这里修复什么?
这段代码对我有用:
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 成为数组。