Skip to content

Instantly share code, notes, and snippets.

@indyarocks
Last active July 15, 2020 09:43
Show Gist options
  • Save indyarocks/3a6439604fe2f4e1331aa7fa98afb930 to your computer and use it in GitHub Desktop.
Save indyarocks/3a6439604fe2f4e1331aa7fa98afb930 to your computer and use it in GitHub Desktop.
DynamoDB Client for Rails Application
## /config/initializers/dynamodb_client.rb
module DynamodbClient
def self.initialize!
client_config = if Rails.env.development?
{
region: 'us-west-2',
endpoint: 'http://localhost:8000'
}
else
{
access_key_id: Rails.application.secrets.dynamodb_access_key_id,
secret_access_key: Rails.application.secrets.dynamodb_secret_access_key,
region: Rails.application.secrets.dynamodb_region
}
end
@@client ||= Aws::DynamoDB::Client.new(client_config)
end
module_function
def client
@@client
end
end
@andreleoni
Copy link

Im getting the follow error:

irb(main):005:0> DynamodbClient.client
Traceback (most recent call last):
        2: from (irb):5
        1: from config/initializers/dynamodb_client.rb:22:in `client'
NameError (uninitialized class variable @@client in DynamodbClient)

@faizaankhan
Copy link

Im getting the follow error:

irb(main):005:0> DynamodbClient.client
Traceback (most recent call last):
        2: from (irb):5
        1: from config/initializers/dynamodb_client.rb:22:in `client'
NameError (uninitialized class variable @@client in DynamodbClient)

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment