I have an SNS topic where I have to add multiple lambda functions as subscriptions. How do i know the arn’s of those multiple functions? How do I loop through?
Currently I am hardcoding the arn’s in list variable. But when we move to PROD we cannot hardcode. Is there a way to get the arn’s for multiple lambda functions?
Code where i am hardcoding the arn’s:
variable “subscription_endpoints”{
default = [
“arn:aws:lambda:us-east-1:2422627334343:function:testsns-s3-notification”,
“arn:aws:lambda:us-east-1:2422627334343:function:testsns-s3-addtags”
]
}
resource “aws_sns_topic” “test-sns-topic”{
name = “test-sns”
delivery_policy = data.template_file.sns_topic-delivery_policy.rendered
}
resource “aws_sns_topic_subscription” “sns_subscriptions” {
count = length(var.subscription_endpoints)>0 ? length(var.subscription_endpoints) : 0
topic_arn = aws_sns_topic.test-sns-topic.arn
protocol = “lambda”
endpoint = var.subscription_endpoints[count.index]
}