aws_apigatewayv2_integration with lambda doesnt work first time

Author: womblepCreated Jul 8, 2022Updated Sep 28, 2026
Labelsstaleservice/apigatewayv2

Very weird issue with aws_apigatewayv2_integration. I create a basic lambda based APIGateway integration using the terraform scripts attached and use postman to call the function. I receive a 500 error and the request doesn't get past the APIGateway. It doesn't show up in the APIGateway logs. I go into the integration via AWS console, remove the lambda and re-select exactly the same lambda and save it, now it works correctly and returns 200 OK. If I do terraform apply, there is no difference between the state that produced a non-working API and the now working one. If I create from scratch (call doesn't work with 500 error), delete the integration completely and run terraform apply again, it creates a working version. Again no major difference in the state files. I have tried using the lambda arn and invoke_arn, same issue

Terraform CLI and Terraform AWS Provider Version

Terraform v1.2.5 on windows_amd64

  • provider registry.terraform.io/hashicorp/archive v2.2.0
  • provider registry.terraform.io/hashicorp/aws v4.22.0

Affected Resource(s)

aws_apigatewayv2_integration

Terraform Configuration Files

NOTE: you will need to change the name of the S3 bucket in the main.tf terraform_aws_api_bug.zip

Debug Output

https://gist.github.com/womblep/6f646d5380952846b3f2a52713d29fdc

Expected Behavior

The config should create an AWS APIGateway that allows the lambda to be called

Actual Behavior

The API Gateway always returns a 500 (until you take the manual steps above)

Steps to Reproduce

  1. terraform apply

Source: hashicorp/terraform-provider-aws