我按照说明进行操作here https://learn.hashicorp.com/tutorials/terraform/lambda-api-gateway用于设置网关和 lambda,但它不起作用。症状似乎与描述的相同here https://stackoverflow.com/questions/63625888/terraform-api-gateway-lambda-integration-trigger-problem但那里建议的修复不起作用。
我的基础设施定义如下:
resource "aws_apigatewayv2_api" "lambda_api" {
name = "${upper(var.project)}-${upper(var.environment)}-${var.gateway_name}"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_stage" "lambda_default" {
name = "$default"
api_id = aws_apigatewayv2_api.lambda_api.id
auto_deploy = true
}
resource "aws_apigatewayv2_integration" "gateway_to_lambda" {
api_id = aws_apigatewayv2_api.lambda_api.id
integration_type = "AWS_PROXY"
connection_type = "INTERNET"
integration_method = "POST"
integration_uri = aws_lambda_function.executable.arn
payload_format_version = "2.0"
}
resource "aws_apigatewayv2_route" "route" {
api_id = aws_apigatewayv2_api.lambda_api.id
route_key = "GET /profile"
target = "integrations/${aws_apigatewayv2_integration.gateway_to_lambda.id}"
}
resource "aws_lambda_permission" "execution_lambda_from_gateway" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.executable.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.lambda_api.arn}/*/*"
}
On the gateway side it looks like things are created correctly: I have an integration that connects my path 'profile' to the lambda:
![enter image description here](https://i.stack.imgur.com/T50Mo.png)
However, when I look on the lambda the trigger is missing:
![enter image description here](https://i.stack.imgur.com/MyUUe.png)
当我尝试访问端点时,我收到一条“内部服务器错误”消息。
当我在 lambda 中手动添加触发器时,它可以工作,但不能在我指定的“配置文件”路由键下工作。
为了将 API 网关中的 /profile 正确路由到我的 lambda,我在这里缺少什么?
根据评论。解决办法是修改权限(消除source_arn
):
resource "aws_lambda_permission" "execution_lambda_from_gateway" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.executable.function_name
principal = "apigateway.amazonaws.com"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)