2

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"
  ]

My python 3.7 code:

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

5
  • You're passing a dictionary in a (or so says the error message) which in turn passes a dictionary as 'Value' in the first dictionary in the list. Commented Jan 14, 2019 at 15:07
  • Please show us the code that is calling this function. Commented Jan 14, 2019 at 21:37
  • i am using lambda with test events: { "key1": "value1", "key2": "value2", "key3": "value3" } Commented Jan 15, 2019 at 2:02
  • i will only trigger this every month end to generate the volume size of each individual s3 bucket, but i got stucked here at the get_metric_statistics. Ironically i can load this python code successfully with exit code 0 in my pycharm CE though Commented Jan 15, 2019 at 2:04
  • @ak86 the test event should be a string, not a dict, most likely a JSON that would then be loaded into a dict. Commented Mar 12, 2019 at 16:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.