I am not able to find terraform module to create AWS SNS Topic subscription. eg: I used "terraform-aws-modules/sns/aws" to create SNS topic. Can someone point me to source module for subscription?
You should prefer resources to modules unless you have a complex use case involving many interacting resources in a common pattern.
Modules are best suited to standardizing common patterns. A module can be made for a single resource, but it's rarely worth the overhead.
Here is a worked example based on a real system. This creates an SNS topic and subscribes a Lambda function to it:
resource "aws_sns_topic" "kpis" {
name = var.sns_topic_name
}
resource "aws_sns_topic_subscription" "invoke_with_sns" {
topic_arn = aws_sns_topic.kpis.arn
protocol = "lambda"
endpoint = module.kpis.function_arn
}
resource "aws_lambda_permission" "allow_sns_invoke" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = module.lambda.function_name
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.kpis.arn
}
You can read more about aws_sns_topic_subscription here: https://www.terraform.io/docs/providers/aws/r/sns_topic_subscription.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.