Last active
July 15, 2020 09:43
-
-
Save indyarocks/3a6439604fe2f4e1331aa7fa98afb930 to your computer and use it in GitHub Desktop.
DynamoDB Client for Rails Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /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 |
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
Im getting the follow error: