Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform Api Gateway Lambda Integration trigger problem

If I manually add an Integration Request of type Lambda function, an Api Gateway trigger is automatically added to the lambda function.

If I do it via Terraform, everything looks correct but when I go look at the Lambda function it has no trigger.

If I then manually update the Integration Request (change to Mock and back to Lambda Function) the trigger is added to the Lambda function? Everything works after that.

What am I missing?

resource "aws_api_gateway_integration" "integration" {
  count = var.lambda_definition.apigateway ? 1 : 0
  rest_api_id = "${data.terraform_remote_state.apigateway.outputs.apigateway_id}"
  resource_id = aws_api_gateway_resource.api_proxy_resource[count.index].id
  http_method = "${aws_api_gateway_method.method[count.index].http_method}"
  integration_http_method = "ANY"
  type                    = "AWS_PROXY"
  uri                     = aws_lambda_function.lambda.invoke_arn
}
like image 494
arranblue Avatar asked Jul 12 '26 14:07

arranblue


1 Answers

Since you've not mentioned whether you specified proper permissions for your function, my guess is that you are missing aws_lambda_permission. This will explicitly give permissions for the api to invoke your function.

The resource would be (example only):

resource "aws_lambda_permission" "allow_api" {
  statement_id  = "AllowAPIgatewayInvokation"
  action        = "lambda:InvokeFunction"
  function_name = aws_lambda_function.lambda.invoke_arn
  principal     = "apigateway.amazonaws.com"
}

When you do it manually in console, the AWS setups all these permissions in the background.

like image 103
Marcin Avatar answered Jul 15 '26 13:07

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!