AWS Lambda - time.time() 返回未定义



我正在使用一个lambda函数,我使用boto3将put_item((放入我的DynamoBD表中,并在代码上添加ttl参数(生存时间(。

ttl = str(int(time.time() + 2629746))

这一行给了我 1 个月的 ttl,但由于某种原因,我收到了很多这样的错误:

An error occurred (ValidationException) when calling the PutItem operation: The parameter cannot be converted to a numeric value: undefined: ClientError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 52, in handler
response = c_put_item(d)
File "/var/task/lambda_function.py", line 40, in c_put_item
'ttl':{'N':ttl}
File "/var/runtime/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutItem operation: The parameter cannot be converted to a numeric value: undefined

知道为什么吗?

PS:我使用 python3

--编辑:

我添加了更多的代码。由于某种原因,这不起作用。

    ttl = str(int(time.time() + 2629746))
    response = client.put_item(TableName='MYTABLENAME',Item={
        'item':{'S':item},
        'title':{'S':title},
        'link':{'S':link},
        'price':{'N':price},
        'category':{'S':category},
        'avaliable':{'S':avaliable},
        'image':{'S':image},
        'ttl':{'N':ttl}
    })

-- 编辑2:

AWS 文档指定您应该像我一样使用 put_item((,除了我被迫使用 str((,因为我收到错误。

@kichik的评论实际上是正确的。此错误并不一定表示 ttl None 。它说整个呼叫的字段之一是None

所以我检测到冲突的字段,我添加了一个异常,问题停止了。

考虑将ttl设为整数:ttl = int(time.time() + 2629746)

Boto3 文档,创建一个新项目:

有关可用于项目的所有有效类型,请参阅有效的 DynamoDB 类型:

这些是用于 Boto3 表资源 (dynamodb.表(和 DynamoDB:
• 整数 – 数字 (N(
•十进制。十进制 – 数字 (N(

最新更新