Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting lambda arn from an external module?

I’m using this module. Specifically, my lambda looks like this:

module "lambda_function_existing_package_s3" {
  source = "terraform-aws-modules/lambda/aws"

  function_name = "lambda"
  description   = "lambda"
  lambda_role    = aws_iam_role.iam_for_lambda.arn
  handler = "lambda_function.lambda_handler"
  runtime = "python3.8"
  timeout = 30

  create_package      = false
  
  s3_existing_package = {
    bucket = var.bucket_id
    key    = "bucket/location"
  }

  vpc_subnet_ids         = [var.subnet1, var.subnet2]
  vpc_security_group_ids = [aws_security_group.allow_egress.id]
  attach_network_policy = true

  environment_variables = {
    1 = "1",
    2 = "2"
  }
}

I’m trying to export the arn of this lambda as SSM, like this:

resource "aws_ssm_parameter" "lambda" {
  name  = "/lambda/arn"
  type  = "String"
  value = module.lambda_function_existing_package_s3.this.arn
}

This is my latest attempt, which throws an error, saying that
this object doesn't have attribute "this", even though the docs mention it. I have also tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

value = module.lambda_function_existing_package_s3.arn, and

value = aws_lambda_function.this.arn

None of it works, and I’m not sure why. I’ve managed to deploy the lambda without errors when I commented out the SSM part, and this is what the output looks like:

name: this  
provider: hashicorp/aws
type: aws_lambda_function   
module: lambda_function_existing_package_s3

What am I missing here?

>Solution :

According to the module outputs documentation, the namespace for the Lambda function ARN value would be module.<declared name>.lambda_function_arn.

resource "aws_ssm_parameter" "lambda" {
  name  = "/lambda/arn"
  type  = "String"
  value = module.lambda_function_existing_package_s3.lambda_function_arn
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading