Terraform - 通过别名调用 lambda 的 URI 是什么? [英] Terraform - what is the URI to invoke lambda via alias?
问题描述
要从 API GW 调用 Lambda,invoke_arn 可用于 aws_lambda_function 资源.
To invoke a Lambda from API GW, invoke_arn can be used for aws_lambda_function resources.
invoke_arn - 用于从 API Gateway 调用 Lambda 函数的 ARN.
invoke_arn - The ARN to be used for invoking Lambda Function from API Gateway.
resource "aws_api_gateway_integration" "videos" {
rest_api_id = "${aws_api_gateway_rest_api.24_hour_video.id}"
resource_id = "${aws_api_gateway_method.videos_get.resource_id}"
http_method = "${aws_api_gateway_method.videos_get.http_method}"
integration_http_method = "GET"
type = "AWS_PROXY" # Lambda Proxy
uri = "${aws_lambda_function.list_videos.invoke_arn}"
}
在 uri 中设置什么以通过别名调用相同的 lambda?
What is to set in uri to invoke the same lambda via an alias?
resource "aws_lambda_alias" "lambda_alias_list_videos" {
name = "get_video_list"
description = "Alias to lambda_list_videos"
function_name = "${aws_lambda_function.list_videos.arn}"
function_version = "$LATEST"
}
推荐答案
aws_lambda_alias
资源创建一个别名,该别名指向特定版本的 Lambda 函数.别名本身是不可调用的.
The aws_lambda_alias
resource creates an alias which points to a specific version of a Lambda function. The alias itself is not invocable.
相反,您应该创建一个指向别名版本的 aws_lambda_function
数据源,并使用其 invoke_arn
属性.您可以在 aws_lambda_function
中使用 qualifier
参数来指定版本或别名(请参阅 AWS Lambda 调用文档了解更多信息).
Instead you should create an aws_lambda_function
Data Source that points to the aliased version, and use its invoke_arn
property. You can use the qualifier
argument in an aws_lambda_function
to specify either a version or an alias name (see AWS Lambda Invoke Docs for more info).
您的示例显示您已经创建了一个名为 get_video_list 的别名,它指向 $LATEST 版本.您需要创建一个指向此别名的新数据源:
Your example shows you have already created an alias named get_video_list, which points to the $LATEST version. You need to create a new Data Source that points to this alias:
data "aws_lambda_function" "my_function_get_video_list" {
function_name = "your-function-name"
qualifier = "get_video_list"
}
您现在可以获取别名函数的调用 ARN:
You can now get the invocation ARN of the aliased function:
${aws_lambda_function.my_function.get_video_list.invoke_arn}
这篇关于Terraform - 通过别名调用 lambda 的 URI 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!