Invoke Lambda from DynamoDB using trigger in terraform.


I have created a Lambda and also DynamoDB.
But now I want to trigger a lambda whenever there is some modification made on a DynamoDB table.
In simple words, I wnat to map the lambd to take event from DynamoDB table.

asked 1 year ago
Reputation: 1

1 Answer


To invoke Lambda from DynamoDB.

Step-1: Create a Lambda Resource

Step-2: Create a DynamoDB table Resource with enable_stream = true.

resource "aws_dynamodb_table" "dynamodb_table" {

  name           = "problem_logs"
  read_capacity  = 20
  write_capacity = 20
  hash_key       = "id"
  stream_enabled = true
  stream_view_type = "NEW_IMAGE"

  attribute {
    name = "id"
    type = "S"

  # Tags
  tags {
    ApplicationOwner = "Astik Anand"
    Environment      = "Development"
    Method           = "Terraform"

Step-3: Create a mapping resource that sets event source of lambda to be DynamoDB.

resource "aws_lambda_event_source_mapping" "lambda_event_maps_dynamodb" {

  event_source_arn  = "${aws_dynamodb_table.jarvis_dynamodb_table.stream_arn}"
  function_name     = "${aws_lambda_function.jarvis_github_event_handlers.arn}"
  starting_position = "LATEST"

answered 1 year ago
Reputation: 1

Your Answer

Nothing to preview

Post Answer

Asked:  1 year ago
Viewed:  1019 times
Active:  1 year ago