AWS Lambda and Gateway API Integration Returns 500 Status Code

First of all, I'm new to overall AWS. I am trying to solve a problem using AWS lambda and API gateway.

  • I created a python lambda function function. It takes some data and returns stringbased on some conditions. Something like below:
def lambda_function(event, context):
    if event['some_property']:
        return "SUCCESS: Operation performed successfully."
    else
        return "ERROR: Operation failed."
  1. In triggers, I configured the gateway API.

  2. In the API gateway service for the created resource, the integration request is configured to go to the lambda function. I checked the lambda function and it returns the values ​​correctly.

  3. But if I twist the API by creating a mail request, it returns a server error. This is a message.

{"message": "internal server error"}

  1. . json application/json , .

, Integration Response -. 200 , .

+4
2

statusCode Lambda. , API- 502 Bad Gateway.

message = {
   'message': 'Execution started successfully!'
}
return {
    'statusCode': 200,
    'headers': {'Content-Type': 'application/json'},
    'body': json.dumps(message)
}

P.S. , . , -!

+1

Source: https://habr.com/ru/post/1663526/


All Articles