我试图让预置并发与我的API网关支持的Lambda函数一起使用。
以下配置不起作用,AWS似乎完全忽略了预置并发,并且会冷启动。
resource "aws_lambda_function" "user_history" {
publish = true
filename = "../distribution/target/distribution/user-history.jar"
function_name = "user-history_${var.user}_${terraform.workspace}"
role = aws_iam_role.lambda.arn
source_code_hash = filebase64sha256("../distribution/target/distribution/user-history.jar")
runtime = "java11"
timeout = 240
memory_size = 512
}
resource "aws_api_gateway_integration" "user_history" {
rest_api_id = aws_api_gateway_rest_api.vnm_api.id
resource_id = aws_api_gateway_resource.user_history.id
http_method = aws_api_gateway_method.user_history.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.user_history.invoke_arn
}
resource "aws_lambda_provisioned_concurrency_config" "user_history_provisioning" {
function_name = aws_lambda_function.user_history.function_name
provisioned_concurrent_executions = 2
count = var.provisioning == true ? 1 : 0
qualifier = aws_lambda_function.user_history.version
}
我猜这可能与未指定版本有关,因此我尝试添加配置项,按照这里的接受答案进行操作,以便调用lambda函数的URI。
resource "aws_lambda_alias" "user_history_alias"{
name = "user_history_version"
description = "Versioned alias"
function_name = aws_lambda_function.user_history.arn
function_version = aws_lambda_function.user_history.version
}
data "aws_lambda_function" "user_history" {
function_name = aws_lambda_function.user_history.function_name
qualifier = "user_history_version"
}
resource "aws_api_gateway_integration" "user_history" {
uri = aws_lambda_function.user_history.user_history_version.invoke_arn
}
但是现在我遇到一个错误,它说:该对象没有名为"user_history_version"的参数、嵌套块或导出属性
有人知道如何让我的预留并发工作吗?
terraform apply
后,您是否看到在AWS Web控制台中创建了设置?您只需要提供2个,因此如果对该函数有3个或更多并发请求,则仍将出现冷启动。 - Mark B