binbashar / terraform-aws-notify-discord

Terraform module which creates SNS topic and Lambda function which sends notifications to Discord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS Notify Discord Terraform module

This module creates an SNS topic (or uses an existing one) and an AWS Lambda function that sends notifications to Discord using the incoming webhooks API.

Start by setting up an incoming webhook integration in your Discord space.

Supported Features

  • AWS Lambda runtime Python 3.9
  • Create new SNS topic or use existing one
  • Support plaintext and encrypted version of Discord webhook URL
  • Most of Discord message options are customizable
  • Various event types are supported, even generic messages:
    • AWS CloudWatch Alarms
    • AWS CloudWatch LogMetrics Alarms
    • AWS GuardDuty Findings

Usage

module "notify_discord" {
  source = "github.com/MefistoBaal/terraform-aws-notify-discord"

  sns_topic_name = "discord-topic"

  discord_webhook_url = "https://discord.com/api/webhooks/XXX/XXXXXXXX"
  discord_username    = "aws"
  discord_avatar_url  = "https://i.imgur.com/eeYUFCO_d.webp"
}

Use existing SNS topic or create new

If you want to subscribe the AWS Lambda Function created by this module to an existing SNS topic you should specify create_sns_topic = false as an argument and specify the name of existing SNS topic name in sns_topic_name.

Examples

Local Development and Testing

See the functions for further details.

Requirements

Name Version
terraform > = 1.1.3
aws > = 3.61

Providers

Name Version
aws > = 3.61

Modules

Name Source Version
lambda terraform-aws-modules/lambda/aws 2.34.0

Resources

Name Type
aws_cloudwatch_log_group.lambda resource
aws_sns_topic.this resource
aws_sns_topic_subscription.sns_notify_discord resource
aws_caller_identity.current data source
aws_iam_policy_document.lambda data source
aws_partition.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
cloudwatch_log_group_kms_key_id The ARN of the KMS Key to use when encrypting log data for Lambda string null no
cloudwatch_log_group_retention_in_days Specifies the number of days you want to retain log events in log group for Lambda. number 0 no
cloudwatch_log_group_tags Additional tags for the Cloudwatch log group map(string) {} no
create Whether to create all resources bool true no
create_sns_topic Whether to create new SNS topic bool true no
iam_policy_path Path of policies to that should be added to IAM role for Lambda Function string null no
iam_role_boundary_policy_arn The ARN of the policy that is used to set the permissions boundary for the role string null no
iam_role_name_prefix A unique role name beginning with the specified prefix string "lambda" no
iam_role_path Path of IAM role to use for Lambda Function string null no
iam_role_tags Additional tags for the IAM role map(string) {} no
kms_key_arn ARN of the KMS key used for decrypting discord webhook url string "" no
lambda_description The description of the Lambda function string null no
lambda_function_name The name of the Lambda function to create string "notify_discord" no
lambda_function_s3_bucket S3 bucket to store artifacts string null no
lambda_function_store_on_s3 Whether to store produced artifacts on S3 or locally. bool false no
lambda_function_tags Additional tags for the Lambda function map(string) {} no
lambda_function_vpc_security_group_ids List of security group ids when Lambda Function should run in the VPC. list(string) null no
lambda_function_vpc_subnet_ids List of subnet ids when Lambda Function should run in the VPC. Usually private or intra subnets. list(string) null no
lambda_role IAM role attached to the Lambda Function. If this is set then a role will not be created for you. string "" no
log_events Boolean flag to enabled/disable logging of incoming events bool false no
recreate_missing_package Whether to recreate missing Lambda package if it is missing locally or not bool true no
reserved_concurrent_executions The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations number -1 no
discord_channel The name of the channel in discord for notifications string n/a yes
discord_emoji A custom emoji that will appear on discord messages string ":aws:" no
discord_username The username that will appear on discord messages string n/a yes
discord_webhook_url The URL of discord webhook string n/a yes
sns_topic_kms_key_id ARN of the KMS key used for enabling SSE on the topic string "" no
sns_topic_name The name of the SNS topic to create string n/a yes
sns_topic_tags Additional tags for the SNS topic map(string) {} no
subscription_filter_policy (Optional) A valid filter policy that will be used in the subscription to filter messages seen by the target resource. string null no
tags A map of tags to add to all resources map(string) {} no

Outputs

Name Description
lambda_cloudwatch_log_group_arn The Amazon Resource Name (ARN) specifying the log group
lambda_iam_role_arn The ARN of the IAM role used by Lambda function
lambda_iam_role_name The name of the IAM role used by Lambda function
notify_discord_lambda_function_arn The ARN of the Lambda function
notify_discord_lambda_function_invoke_arn The ARN to be used for invoking Lambda function from API Gateway
notify_discord_lambda_function_last_modified The date Lambda function was last modified
notify_discord_lambda_function_name The name of the Lambda function
notify_discord_lambda_function_version Latest published version of your Lambda function
discord_topic_arn The ARN of the SNS topic from which messages will be sent to discord
this_discord_topic_arn The ARN of the SNS topic from which messages will be sent to discord (backward compatibility for version 4.x)

Authors

Module is maintained by Santiago Hurtado with help from these awesome contributors .

License

Apache 2 Licensed. See LICENSE for full details.

About

Terraform module which creates SNS topic and Lambda function which sends notifications to Discord


Languages

Language:Python 77.2%Language:HCL 22.8%