0

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 2

1

I would create an environment variable for your lambda containing the ARN of your SNS topic. Then lambda function can read that variable and use it accordingly.

Sign up to request clarification or add additional context in comments.

Comments

0

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.