Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rhuang opened this issue Jan 7, 2025 · 6 comments

Comments

@rhuang
Copy link

rhuang commented Jan 7, 2025

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

@andrykonchin
Copy link
Member

andrykonchin commented Jan 8, 2025

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

@rhuang
Copy link
Author

rhuang commented Jan 8, 2025

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

@andrykonchin
Copy link
Member

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
Copy link
Member

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

@rhuang
Copy link
Author

rhuang commented Jan 9, 2025

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.

@ckhsponge
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants