lambda python dynamodb写入获取超时错误 [英] lambda python dynamodb write gets timeout error

查看:107
本文介绍了lambda python dynamodb写入获取超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试完成有关lambda dynamodb连接的第一个教程,并且遇到超时错误。

I have been trying to work through my first tutorial on lambda dynamodb connections and am running into a timeout error.

在lambda控制台中,我有以下代码:

In the lambda console I have the following code:

from __future__ import print_function
import json
import boto3

print('Loading function')

def lambda_handler(event, context):

    dynamodb = boto3.resource('dynamodb', region_name='us-east-1', endpoint_url="http://localhost:8000")
    print('Dynamodb loaded')
    pages_table = dynamodb.Table('Pages')
    print('Pages table referenced')

    for item in event:
        print('Item: {}'.format(item))
        response = pages_table.put_item( Item=item)
        print('Response: {}'.format(response))

    return "hi"

我通过dynamodb控制台创建了Pages表。

I have created the Pages table via the dynamodb console.

当我从lambda控制台测试运行lambda函数时,我g et:

When I test run the lambda function from the lambda console, I get:

START RequestId: 4008f77f-3b3e-11e7-ad79-0713f3bd7f4e Version: $LATEST
Dynamodb loaded
Pages table referenced
Item: {'UID': 1, 'id': 1, 'label': 'Original', 'snippet': 'Style', 'type': 'item', '$$hashKey': 'object:4'}
END RequestId: 4008f77f-3b3e-11e7-ad79-0713f3bd7f4e
REPORT RequestId: 4008f77f-3b3e-11e7-ad79-0713f3bd7f4e  Duration: 3002.30 ms    
Billed Duration: 3000 ms    Memory Size: 128 MB Max Memory Used: 36 MB  
2017-05-17T20:20:24.159Z 4008f77f-3b3e-11e7-ad79-0713f3bd7f4e Task timed out after 3.00 seconds

我的调试打印语句表明,第一个 pages_table.put_item()是发生超时的地方,因为没有后续打印响应。 (我的Item数组中有一些要测试的元素)

My debugging print statements indicate that the very first pages_table.put_item() is where the timeout happens since there is no subsequent print of the response. (I have a few elements in my Item array for testing)

当我检查dynamodb表时,即使几天后,表中也没有数据。

When I check my dynamodb table there is no data in the table, even days later.

我想我已经准确地遵循了AWS文档中的所有步骤来创建可通过lambda访问的dynamodb(IAM权限,dynamodb表键等),但是在搜索其他内容时却陷入困境超时的类似经历的实例。我能找到的最接近的东西是VPC配置,但是对于本教程中的这种默认设置来说,这对我来说似乎没有意义,因为这些教程并未提及VPC设置。另外,当我进入VPC控制台时,设置似乎是默认设置。

I think I have accurately followed all the steps in the AWS documentation for creating a dynamodb accessible via lambda (IAM permissions, dynamodb table keys, etc), but have been stumped when searching for other instances of similar experiences with timeouts. The closest things I can find references VPC configuration, but that doesn't seem to make sense for me with this essentially default setup from the tutorials since the tutorials didn't mention VPC setup. Also, when I dug into the VPC console the settings there appeared to be default.

我缺少什么?

推荐答案

DynamoDB的端点URL似乎不正确:

The endpoint URL for DynamoDB seems to be incorrect:

endpoint_url="http://localhost:8000"

这仅用于DynamoDB的本地测试。通过Lambda函数,us-east-1的终结点必须为:

This is used only for local testing of DynamoDB. From Lambda function, the endpoint for us-east-1 needs to be:

endpoint_url="https://dynamodb.us-east-1.amazonaws.com"

根据 AWS区域和端点文档。

这篇关于lambda python dynamodb写入获取超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆