簡體   English   中英

如何從 AWS Lambda python 響應中解析出值?

[英]How do I parse out value from AWS Lambda python response?

我試圖讓“counter_value”數字傳遞到我的 API 網關。 這是我從 lambda function 返回響應時當前傳入的內容

{"Attributes": {"counter_value": {"N": "89"}}, "ResponseMetadata": {"RequestId": "OOQNNHDS4S5E2IPHHA6PHVGS0JVV4KQNSO5AEMVJF66Q9ASUAAJG", "HTTPStatusCode": 200, "HTTPHeaders": {"server": "Server", "date": "Tue, 21 Jul 2020 01:58:26 GMT", "content-type": "application/x-amz-json-1.0", "content-length": "43", "connection": "keep-alive", "x-amzn-requestid": "OOQNNHDS4S5E2IPHHA6PHVGS0JVV4KQNSO5AEMVJF66Q9ASUAAJG", "x-amz-crc32": "897850636"}, "RetryAttempts": 0}}

這是我的 Lambda 函數(Python)

import boto3
def lambda_handler(event, context):
    dynamodb = boto3.client('dynamodb')
    
    response = dynamodb.update_item(
        TableName = 'Ordeproject',
        Key = {
            'id': {'S':'counter'}
        },
        UpdateExpression = 'SET counter_value = counter_value + :add',
        ExpressionAttributeValues = {
            ':add': {'N':'1'}
        },
        ReturnValues = "UPDATED_NEW"
    )
    print("UPDATING ITEM")
    print(response)
    return response

也許我誤解了這個問題,但是要從response中獲取counter_value ,您可以執行以下操作:

counter_value = response['Attributes']['counter_value']['N']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM