简体   繁体   English

lambda python dynamodb write获取超时错误

[英]lambda python dynamodb write gets timeout error

I have been trying to work through my first tutorial on lambda dynamodb connections and am running into a timeout error. 我一直在努力完成关于lambda dynamodb连接的第一个教程并遇到超时错误。

In the lambda console I have the following code: 在lambda控制台中,我有以下代码:

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"

I have created the Pages table via the dynamodb console. 我通过dynamodb控制台创建了Pages表。

When I test run the lambda function from the lambda console, I get: 当我测试从lambda控制台运行lambda函数时,我得到:

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

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. 我的调试打印语句表明,第一个pages_table.put_item()是超时发生的地方,因为没有后续的响应打印。 (I have a few elements in my Item array for testing) (我的Item数组中有一些元素用于测试)

When I check my dynamodb table there is no data in the table, even days later. 当我检查我的dynamodb表时,表中没有数据,即使是几天之后。

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. 我认为我已经准确地遵循AWS文档中的所有步骤来创建可通过lambda访问的dynamodb(IAM权限,dynamodb表键等),但在搜索具有超时的类似体验的其他实例时却被困住了。 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. 我能找到的最接近的东西引用了VPC配置,但是对于我来说这对我来说似乎没有意义,因为教程没有提到VPC设置。 Also, when I dug into the VPC console the settings there appeared to be default. 此外,当我挖到VPC控制台时,那里的设置似乎是默认的。

What am I missing? 我错过了什么?

The endpoint URL for DynamoDB seems to be incorrect: DynamoDB的端点URL似乎不正确:

endpoint_url="http://localhost:8000"

This is used only for local testing of DynamoDB. 这仅用于DynamoDB的本地测试。 From Lambda function, the endpoint for us-east-1 needs to be: 从Lambda函数来看,us-east-1的端点需要是:

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

As per the AWS Regions and Endpoints document. 根据AWS Regions和Endpoints文档。

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

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