简体   繁体   English

Terraform 模块创建 AWS SNS 主题订阅

[英]Terraform module to create AWS SNS Topic Subscription

I am not able to find terraform module to create AWS SNS Topic subscription.我找不到 terraform 模块来创建 AWS SNS 主题订阅。 eg: I used "terraform-aws-modules/sns/aws" to create SNS topic.例如:我使用“terraform-aws-modules/sns/aws”来创建 SNS 主题。 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:这将创建一个 SNS 主题并为其订阅 Lambda function:

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您可以在此处阅读有关aws_sns_topic_subscription的更多信息: https://www.terraform.io/docs/providers/aws/r/sns_topic_subscription.ZFC35FDC70D5FC69D269883A8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM