本文介绍了如何使用 Terraform 获取 AWS Lambda ARN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试定义一个返回 Lambda 函数的 ARN 的 terraform 输出块.Lambda 在子模块中定义.根据文档,似乎 lambda 应该已经有一个 ARN 属性:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function#arn

I am trying to define a terraform output block that returns the ARN of a Lambda function. The Lambda is defined in a sub-module. According to the documentation it seems like the lambda should just have an ARN attribute already: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function#arn

使用它作为来源,我认为我应该能够做到以下几点:

Using that as a source I thought I should be able to do the following:

output "lambda_arn" {
  value = module.aws_lambda_function.arn
}

这会产生以下错误:

Error: Unsupported attribute

  on main.tf line 19, in output "lambda_arn":
  19:   value = module.aws_lambda_function.arn

This object does not have an attribute named "arn".

如果有任何意见,我将不胜感激,谢谢.

I would appreciate any input, thanks.

推荐答案

文档正确.数据源 data.aws_lambda_function 具有 arn 属性.但是,您正尝试从自定义模块 module.aws_lambda_function 访问 arn.为此,您必须在模块中定义输出 arn.

Documentation is correct. Data source data.aws_lambda_function has arn attribute. However, you are trying to access the arn from a custom module module.aws_lambda_function. To do this you have to define output arn in your module.

所以在你的模块中你应该有这样的东西:

So in your module you should have something like this:

data "aws_lambda_function" "existing" {
  function_name = "function-to-get"
}

output "arn" {
  value = data.aws_lambda_function.existing.arn
}

如果你的模块名为 aws_lambda_function:

module "aws_lambda_function" {
   source = "path-to-module"
}

您将能够访问 arn:

module.aws_lambda_function.arn

这篇关于如何使用 Terraform 获取 AWS Lambda ARN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 13:10