运行AWS Lambda(将uuid转换为字符串)w / Dynamo DB时出现str()错误

时间:2016-02-25 20:31:58

标签: python amazon-web-services amazon-dynamodb aws-lambda boto3

我在下面的代码中尝试将uuid转换为字符串,但我总是遇到错误。无论我是否与uuid.uuid4()分别声明str() 请参阅下面的代码:

    from __future__ import print_function
    from decimal import *
    import boto3
    import json
    from locale import str
    import uuid

    def my_handler(event, context):
        description = event['description'] 
        spot_id = uuid.uuid4() #Unique identifier for spot 
        dynamodb = boto3.client('dynamodb')
        tablesinfo = "sinfo"
        dynamodb.put_item(
        TableName = tablesinfo, Item = {
          'spot_id':{'S' : str(spot_id)},
          'description': {'S' : description
          }
        )
        return {'spot_id' : spot_id}

这些是我收到的错误:

{
  "stackTrace": [
    [
      "/var/task/Create_Spot_Test.py",
      15,
      "my_handler",
      "'spot_id':{'S' : str(spot_id)},"
    ],
    [
      "/usr/lib64/python2.7/locale.py",
      303,
      "str",
      "return format(\"%.12g\", val)"
    ],
    [
      "/usr/lib64/python2.7/locale.py",
      196,
      "format",
      "return _format(percent, value, grouping, monetary, *additional)"
    ],
    [
      "/usr/lib64/python2.7/locale.py",
      202,
      "_format",
      "formatted = percent % value"
    ]
  ],
  "errorType": "TypeError",
  "errorMessage": "float argument required, not UUID"
}

1 个答案:

答案 0 :(得分:1)

不需要

from locale import str(导入以前的错误)

此外,您必须先将uuid = uuid.uuid4()声明为变量,然后声明另一个变量,将其转换为字符串spot_id = str(uuid),而不是内联str()