dynamoid icon indicating copy to clipboard operation
dynamoid copied to clipboard

am I able to configure API calls to use different set of AWS credentials, table, with the same model?

Open rhuang opened this issue 10 months ago • 6 comments

I want to do something like this:

env1_results = MyModel.find(...) # where table name is TEST_MY_MODEL
env2_results = MyModel.find(...) # where table name is ALPHA_MY_MODEL and a different set of AWS credentials

Is this possible?

Currently, Dynamoid is configured with Dynamoid.configure and Aws.config.update

rhuang avatar Jan 07 '25 17:01 rhuang

Right now it isn't supported. Could you please describe your use case? There is a similar issue - #403 and a discussion #509.

andrykonchin avatar Jan 08 '25 20:01 andrykonchin

Thank you, we have a similar use case to #403 where we need to access multiple accounts' tables with the same model.

rhuang avatar Jan 08 '25 21:01 rhuang

Is switching to an AWS account that you need temporary and local? And a desirable API is close to the second option from the #403:

Dynamoid.configure(config_options) do
  User.count
end

andrykonchin avatar Jan 08 '25 22:01 andrykonchin

I am looking at the Rails Multiple Databases with Active Record guide - they provide means to dynamically switch to some predefined database shard in the similar way:

ActiveRecord::Base.connected_to(role: :writing, shard: :shard_one) do
  Person.find(@id) # Can't find record, doesn't exist because it was created
                   # in the shard named ":default".
end

andrykonchin avatar Jan 08 '25 22:01 andrykonchin

Thanks for clarifying. I would require the second option as you mentioned. Following your example, I need to get the same model,User.count from different AWS accounts.

Is switching to an AWS account that you need temporary and local?

No, we maintain large amounts of accounts in our staging environment that is semi-produciton, that we regularly configure and sync to and from production. I've been using a hodgepodge of "copy to environment" APIs and the DynamoDB Ruby SDK, but they are getting out of control and would much prefer to work with Dynamoid models directly to query and write for cross-account data.

rhuang avatar Jan 09 '25 22:01 rhuang

@rhuang I think you should be able to do this with cross-account permissions.

  1. In your staging account give write access to the production account for the DynamoDB table.
  2. On the production account codebase, extend a model and set the table name to the ARN of a staging table

ckhsponge avatar Jan 09 '25 22:01 ckhsponge