Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get AWS Lambda ARN using Terraform?

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
}

This generates the following error:

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.

like image 205
Cogito Ergo Sum Avatar asked Apr 27 '26 05:04

Cogito Ergo Sum


1 Answers

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
}

Then if you have your module called aws_lambda_function:

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

you will be able to access the arn:

module.aws_lambda_function.arn
like image 175
Marcin Avatar answered Apr 30 '26 04:04

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!