First of all, I am new to whole AWS itself. I am trying to solve a problem using AWS lambda and API Gateway.
string
based 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."
Under the triggers , I set up a gateway API.
In API gateway service for the created resource, the integration request is configured to pass through to the lambda function. I have tested lambda function and it returns values properly.
But if i curl the API making a post request, it returns a server error. The message is this.
{"message": "internal server error"}
application/json
and use empty model template for it, then it works fine.I guess , I am missing something in Integration Response part. What i want is to return a 200
status code along with the success message, if the operation is performed successfully.
You need to pass the statusCode
after executing the Lambda function. If you don't pass it the API Gateway will trigger 502 Bad Gateway
by default.
message = {
'message': 'Execution started successfully!'
}
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps(message)
}
I'd first suggest using the 'proxy' Lambda integration. It is much easier to configure and use. Here are docs for that http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html and http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html
But it sounds like you don't have the responses mapped correctly. Hard to say from your description what the issue is, but you can use the example "Petstore API" to see what the responses should look like. That may be helpful. You can see that option in the 'Create API' screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With