Reputation: 41
I have been getting this error for days and unable to sort out whats the issues on this code:
"errorMessage": "Parameter validation failed:\nInvalid type for parameter Dimensions[0].Value, value: {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}, type: <class 'dict'>, valid types: <class 'str'>",
"errorType": "ParamValidationError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 26, in bucket_size\n Unit='Bytes'\n",
" File \"/var/runtime/botocore/client.py\", line 320, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 596, in _make_api_call\n api_params, operation_model, context=request_context)\n",
" File \"/var/runtime/botocore/client.py\", line 632, in _convert_to_request_dict\n api_params, operation_model)\n",
" File \"/var/runtime/botocore/validate.py\", line 291, in serialize_to_request\n raise ParamValidationError(report=report.generate_report())\n"
]
import boto3
from datetime import datetime, timedelta
import json
def bucket_size(a, b):
bucket_name = a
cloudwatch = boto3.client('cloudwatch',region_name='ap-southeast-1')
response = cloudwatch.get_metric_statistics(
Namespace="AWS/S3",
MetricName="BucketSizeBytes",
Dimensions=[
{
'Name': 'BucketName',
'Value': bucket_name
},
{
'Name': 'StorageType',
'Value': 'StandardStorage'
}
],
Statistics=['Average'],
Period=86400,
StartTime=datetime.now()-timedelta(days=10),
EndTime=datetime.now()-timedelta(days=2),
Unit='Bytes'
)
i am trying to get the metric from S3 and pipe to a .csv file on specific S3 bucket, but i encounter this error on lambda python 3.7
Any help appreciated, open alot of tabs to find answers online but not available, thanks and appreciated ! Cheers
Upvotes: 2
Views: 10698
Reputation: 19
Not sure but i think is on
Dimensions=[
{
'Name': 'BucketName',
'Value': bucket_name
},
{
'Name': 'StorageType',
'Value': 'StandardStorage'
}
]
You are passing a list of dicts objects and module is expecting a list of string objects.
Upvotes: 1