1

Im trying to get the "counter_value" number to be passed into my API gateway. This is what is currently passed in when I return response from my 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}}

Here is my Lambda Function(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

1 Answer 1

2

Maybe I misunderstand the issue, but to get the counter_value from response you can do the following:

counter_value = response['Attributes']['counter_value']['N']
Sign up to request clarification or add additional context in comments.

2 Comments

That was exactly what I was trying to do!
@Ordep81 Happy to hear that:-) Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.