I've got a Terraform file that creates an AWS Lambda and an AWS SNS Topic. The lambda sends a message to the SNS topic. At the moment I have hardcoded the ARN for the SNS Topic in the lambda. Is there anyway of getting the lambda to pickup the ARN from Terraform instead?
2 Answers
I found something that might help you or give you an idea, but SQS is also used in that Terraform.
#resources.tf
resource "aws_sns_topic" "results_updates" {
name = "results-updates-topic"
}
resource "aws_sqs_queue" "results_updates_queue" {
name = "results-updates-queue"
redrive_policy = "{\"deadLetterTargetArn\":\"${aws_sqs_queue.results_updates_dl_queue.arn}\",\"maxReceiveCount\":5}"
visibility_timeout_seconds = 300
tags = {
Environment = "dev"
}
}
resource "aws_sqs_queue" "results_updates_dl_queue" {
name = "results-updates-dl-queue"
}
resource "aws_sns_topic_subscription" "results_updates_sqs_target" {
topic_arn = "${aws_sns_topic.results_updates.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.results_updates_queue.arn}"
}
Hope this helps :)