Last active
November 19, 2021 09:05
-
-
Save rts-rob/9de1d8e91ed91e32bea6236da2308914 to your computer and use it in GitHub Desktop.
Simple Terraform example with one DynamoDB table and one Lambda function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { } | |
resource "aws_iam_role" "iam_for_lambda" { | |
name = "iam_for_lambda" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "lambda.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} | |
EOF | |
} | |
resource "aws_lambda_function" "someFunction" { | |
filename = "lambda_function_someFunction.zip" | |
function_name = "lambda_function_name" | |
role = "${aws_iam_role.iam_for_lambda.arn}" | |
handler = "exports.handler" | |
source_code_hash = "${base64sha256(file("lambda_function_someFunction.zip"))}" | |
runtime = "nodejs6.10" | |
} | |
resource "aws_dynamodb_table" "someTable" { | |
name = "someTable" | |
read_capacity = 5 | |
write_capacity = 5 | |
hash_key = "id" | |
range_key = "version" | |
stream_enabled = true | |
stream_view_type = "NEW_AND_OLD_IMAGES" | |
attribute { | |
name = "id" | |
type = "S" | |
} | |
attribute { | |
name = "version" | |
type = "N" | |
} | |
} | |
resource "aws_lambda_event_source_mapping" "event_source_mapping" { | |
batch_size = 100 | |
event_source_arn = "${aws_dynamodb_table.someTable.arn}" | |
enabled = true | |
function_name = "${aws_lambda_function.someFunction.function_name}" | |
starting_position = "TRIM_HORIZON" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment