AWS API gateway not passing data into lambda function upon invocation

0 votes

I'm not familiar with Lambda or APIs, but I'm trying to use my API to execute a PUT operation and call a lambda code to update a DynamoDB table. When I test my lambda function using a JSON event, it operates as intended.

import boto3
import json


def updateScore(event, context):
    
    dynamodb_client = boto3.client('dynamodb', region_name='us-east-1')
    dynamodb_resource = boto3.resource('dynamodb', region_name='us-east-1')
    table = dynamodb_resource.Table('Highscore')
    score = event["Highscore"]
    print(event.keys())
    response = table.update_item(
     Key={'ID': 0},
     ExpressionAttributeNames = {"#hs": "Highscore"},
     UpdateExpression="SET #hs = :val1",
     ExpressionAttributeValues={":val1": score}
     )

    return {
            "statusCode": 200,
            "headers": {
                'Access-Control-Allow-Headers': 'application/json',
                'Access-Control-Allow-Origin': '*',
                'Access-Control-Allow-Methods': 'PUT'
            },
            'body': event['Highscore']
        }


with the JSON object test event

{
  "ID": 0,
  "Highscore": 1
}

The code correctly updates my table, but when I try to test the function using the API gateway, it behaves as if the event provided by the gateway does not exist (I say this because in the logs it shows a Key Error on the event parameter indicating that it does not exist). I receive an internal server error 502 on both the test in the AWS console and on Postman. The identical information that was in the event JSON object is what I am delivering in the body, however it is still not working. Thank you for your assistance.

Dec 20, 2022 in Cloud Computing by Tejashwini
• 3,820 points
394 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Cloud Computing

0 votes
1 answer

What approach do I need to take to upload files to Lambda function and API Gateway services?

If you want to upload bigger than ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,200 points
841 views
+1 vote
2 answers

AWS: API Gateway Encoding for multipart/form-data

API Gateway now supports binary payloads. Simply ...READ MORE

answered Aug 22, 2018 in Cloud Computing by Priyaj
• 58,020 points
6,540 views
+3 votes
3 answers

Is it possible to delete a API in AWS API Gateway?

Yes, it is possible to delete an ...READ MORE

answered Mar 27, 2018 in Cloud Computing by brat_1
• 7,200 points
4,766 views
+4 votes
3 answers

AWS API Gateway with AWS WAF

Well that is not possible, Reason: API Gateway would ...READ MORE

answered Mar 27, 2018 in Cloud Computing by code_ninja
• 6,300 points
1,852 views
+4 votes
3 answers

Deploy RESTful API with .net framework 4.5 in AWS Lambda

This is an old question (somewhat), but ...READ MORE

answered Jan 17, 2019 in Cloud Computing by Kirk Davis
3,213 views
0 votes
1 answer

Can we Use Api keys with AWS API Gateway?

There is no getting away here. When ...READ MORE

answered Apr 18, 2018 in Cloud Computing by hemant
• 5,790 points
541 views
0 votes
1 answer
0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,020 points
10,120 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP