Questions

Invoke Lambda from DynamoDB using trigger in terraform.

0

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 10 months, 3 weeks ago
Reputation: 1





1 Answer

0

To invoke Lambda from DynamoDB.

Step-1: Create a Lambda Resource
(aws_lambda_function)

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

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 10 months, 3 weeks ago
Reputation: 1





Your Answer

Nothing to preview

Post Answer



Asked:  10 months, 3 weeks ago
Viewed:  795 times
Active:  10 months, 3 weeks ago