Skip to content

Commit

Permalink
Merge pull request #86 from overmindtech/sns
Browse files Browse the repository at this point in the history
Sns
  • Loading branch information
dylanratcliffe authored Mar 6, 2024
2 parents 125e866 + 2fda1cf commit 7f4d367
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions modules/scenarios/sns_lambda.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This example is to detect that we can show that Overmind will be able to
# detect that removing an SNS topic will affect a lambda even if it's not
# managed in terraform

data "archive_file" "lambda_zip" {
type = "zip"
output_path = "${path.module}/tmp/lambda_function.zip"

source {
content = <<EOF
exports.handler = async (event) => {
console.log("Event: ", event);
return {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
};
EOF
filename = "index.js"
}
}

resource "aws_iam_role" "lambda_iam_role" {
name = "example_lambda_iam_role"

assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "sts:AssumeRole",
Principal = {
Service = "lambda.amazonaws.com",
},
Effect = "Allow",
Sid = "",
},
],
})
}

resource "aws_lambda_function" "example" {
function_name = "example_lambda_function"
filename = data.archive_file.lambda_zip.output_path
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
role = aws_iam_role.lambda_iam_role.arn
handler = "index.handler"
runtime = "nodejs20.x"
}

resource "aws_sns_topic" "example_topic" {
name = "example-topic"
}

# resource "aws_lambda_permission" "allow_sns" {
# statement_id = "AllowExecutionFromSNS"
# action = "lambda:InvokeFunction"
# function_name = aws_lambda_function.example.function_name
# principal = "sns.amazonaws.com"
# source_arn = aws_sns_topic.example_topic.arn
# }
Binary file added modules/scenarios/tmp/lambda_function.zip
Binary file not shown.

0 comments on commit 7f4d367

Please sign in to comment.