Infra & Cloud terraform Advanced

AWS Lambda with API Gateway

Terraform for a Lambda function exposed via API Gateway v2 HTTP API.

terraform
resource "aws_lambda_function" "fn" {
  function_name = var.name
  filename      = data.archive_file.fn.output_path
  handler       = "index.handler"
  runtime       = "nodejs20.x"
  role          = aws_iam_role.lambda.arn
}
resource "aws_apigatewayv2_api" "api" {
  name          = "${var.name}-api"
  protocol_type = "HTTP"
}
resource "aws_apigatewayv2_integration" "fn" {
  api_id           = aws_apigatewayv2_api.api.id
  integration_type = "AWS_PROXY"
  integration_uri  = aws_lambda_function.fn.invoke_arn
}

Prerequisites

  • terraform >= 1.0
  • AWS provider

Pro Tips

  • → Grant API Gateway invoke permission with aws_lambda_permission.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
terraform
Level
Advanced
Read time
6 min
Published
Dec 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.