简体   繁体   English

Lambda python 3.7:参数验证失败:\\ n参数Dimensions [0]的类型无效

[英]Lambda python 3.7 : Parameter validation failed:\nInvalid type for parameter Dimensions[0]

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: 我的python 3.7代码:

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 我正在尝试从S3获取指标并将其传递到特定S3存储桶上的.csv文件,但是我在lambda python 3.7上遇到此错误

Any help appreciated, open alot of tabs to find answers online but not available, thanks and appreciated ! 感谢您的帮助,请打开许多标签以在线查找答案,但不可用,谢谢! Cheers 干杯

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. 您正在传递字典对象列表,而模块期望使用字符串对象列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM