首页 > 解决方案 > Dynamodb 触发器使用 lambda 更新另一个 dynamobo 表

问题描述

我正在为我的 lambda 使用 dynamodb 触发器。所以我正在考虑两个条件,每当我的表 1 更新时,应该触发 lambda,并根据条件表达式更新表 2,就像我在表 2 中应用的更改一样。因为我是要使用 boto 3 资源需要对示例逻辑进行相同的重新分级。我是使用 dynamodb 触发器处理事件的新手。任何帮助将不胜感激。

标签: amazon-web-servicesaws-lambda

解决方案


Table-1 ~~~~~~~~> AWS Lambda --------->Table2

Event received by AWS Lambda will look something like this. What you need to do is based on event name process the values present and store it in Table-2.

def lambda_handler(event, context):
    dynamodb = boto3.resource('dynamodb', region_name='eu-west-1')
    table2 = dynamodb.Table('Table-2')

    # Read the records in the event
    for record in event['Records']:
        # process record and prepare required object for Table-2
        table_2_obj = process_record(record)
        put_item_response = table2.put_item(table_2_obj)
        # Verify the response if required
        print(put_item_response)

推荐阅读