Permissions issue when two different lambdas/jobs that use "dynamodb_event" for different tables

I have something like this:

class TestJob < ApplicationJob
  dynamodb_event "test-table" # existing table

  def file
    puts "event #{JSON.dump(event)}"
  end
end

class AnotherJob < ApplicationJob
  dynamodb_event "another-table" # existing table

  def file
    puts "event #{JSON.dump(event)}"
  end
end

When either one of the lambdas/jobs run, I get a “Aws::DynamoDB::Errors::AccessDeniedException”, I assume because the dynamodb_event method runs for both classes, even though the actual lambda function that’s running only needs one of them. Right now, I’m just rescuing the error and that seems to work, but it seems like it would be preferable to not run the dynamodb_event method for code that the current lambda doesn’t need.

By default, does every lambda function require that all the code in the whole project be loaded + any macros like this be run on every lamba function call?

I’m wondering if I’m missing something in terms of configuration or if maybe there’s a way to know the current lambda function and maybe wrap that dynamodb_event method call in a condition.

It looks like i can also side step this issue by passing in the full stream arn.

1 Like