Michael Sync

Michael Sync

Crisp, minimal personal blog

19 Aug 2021

AWS API Gateway + Lambda: 500 Internal server error or Invalid permissions on Lambda function


Background

I have an .NET Core Web API hosted on the AWS Lambda. I put the AWS Gateway in front.

Problem

I am getting the “500 Internal Server Error” when accessing the Web API’s swagger url. We already checked the API/Lambda invoke permission. If you are not sure, you can check this link

Solution

The solution is that you need to redeploy your API gateway.

Redeploy your API gateway

If you are using Terraform to deploy the AWS AG, you need to this code.

1
2
3
4
5
6
7
8
9
/* 
    Forcing the API deployment even there is no change. 
    We will might have to explore this option ``redeployment = sha1(jsonencode([ in future```
    https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment#terraform-resources
  */

  variables = {
     deployed_at = "${timestamp()}" 
  }

If it’s the permission, you can confirm by looking at this message “Invalid permissions on Lambda function” in the CloudWatch log.

Invalid permissions on Lambda function