flowermia
flowermia

Reputation: 409

Internal Server Error on Terraform provisioned API Gateway Trigger

I'm using Terraform to allocate a Lambda function that's triggered by a request to an API Gateway on AWS. Here's my .tf file:

dsf

This correctly sets up the Lambda function, but something is off with the API Gateway. When I curl with the output URL (https://cqsso4fw67.execute-api.us-east-1.amazonaws.com), it gives me the following:

curl https://cqsso4fw67.execute-api.us-east-1.amazonaws.com/
{"message":"Internal Server Error"}%  

If I manually remove this API Gateway and create a new one from the AWS Console within the Lambda function and run curl again, I get "SUCCESS!" (which is what my Lambda should do).

smf        

Any ideas how I can fix the .tf file to correctly setup the API Gateway trigger?

Here are the differences between the one created in AWS and the one provisioned in Terraform. Terraform one is at the top.

enter image description here

Upvotes: 0

Views: 894

Answers (2)

flowermia
flowermia

Reputation: 409

If anyone comes across this issue, I managed to fix it by greatly simplifying things. I switched out all the API Gateway clauses in the Terraform file with just:

resource "aws_apigatewayv2_api" "apigw-terraform" {
    name          = "terraform-api"
    protocol_type = "HTTP"
    target        = aws_lambda_function.w-scan-terraform.arn
}

The tutorial I was following had implemented something more complex than what I needed.

Upvotes: 0

Marcin
Marcin

Reputation: 238091

The TF code that you showed is correct. Most likely reason for the failure is your lambda function, which you haven't showed. You have to inspect lambda function logs in CloudWatch to check why it fails.

Edit:

The function should return:

    return {                                                                                                                                                                                                  
        'statusCode': 200,                                                                                                                                                                                    
        'body': 'SUCCESS'                                                                                                                                                                                     
    } 

Upvotes: 1

Related Questions