2017-08-08 8 views
0

レール5では、ダイナモブロックの機能を設定する必要があります。私はいくつかのブログを参照し、それを実装しようとしました。まず、ローカルホストで、それはどんな問題なく走っていたが、私は他の新しいシステムやサーバーに移動するとき、それはのようなエラーを示している、ダイナモをレールに設定するにはどうすればいいですか?

/home/NICHEPRO/shruthir/.rvm/gems/ruby-2.4.0/gems/aws-sdk-core-2.10.19/lib/aws-sdk-core/plugins/regional_endpoint.rb:34:in `after_initialize': missing region; use :region option or export region name to ENV['AWS_REGION'] (Aws::Errors::MissingRegionError) 
from /home/NICHEPRO/shruthir/.rvm/gems/ruby-2.4.0/gems/aws-sdk-core-2.10.19/lib/seahorse/client/base.rb:84:in `block in after_initialize' 

AWSの宝石は、から参照

aws-sdk (2.10.19) 
aws-sdk-core (2.10.19) 
aws-sdk-resources (2.10.19) 

次のとおりです。

https://assist-software.net/snippets/how-save-data-amazon-dynamodb-using-ruby-on-rails

また、私は他のブログを参照して、この問題を解決することを試みたが、私はあまりにもエラーの下になります、

Failed to open TCP connection to localhost:8080 (Connection refused - connect(2) for "localhost" port 8080) 

この問題を解決するにはどうすればよいですか?

答えて

1

あなたはダイナモイド宝石を使用していますか? app/config/initializerに新しい設定ファイルを追加し、以下のコードを追加してください。

Dynamoid.configure do |config| 
    config.adapter = 'aws_sdk_v2' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem. 
    config.access_key = (ENV['AWS_ACCESS_KEY_ID'] || APP_CONFIG[:aws_access_key_id]) 
    config.secret_key = (ENV['AWS_SECRET_ACCESS_KEY'] || APP_CONFIG[:aws_secret_access_key]) 
    config.region = (ENV['AWS_REGION'] || 'us-east-1') 
    config.namespace = nil # To namespace tables created by Dynamoid from other tables you might have. Set to nil to avoid namespacing. 
    config.warn_on_scan = true # Output a warning to the logger when you perform a scan rather than a query on a table. 
    config.read_capacity = 100 # Read capacity for your tables 
    config.write_capacity = 200 # Write capacity for your tables 
    config.endpoint = (ENV['DYNAMO_ENDPOINT'] || APP_CONFIG[:dynamo_endpoint]) # [Optional]. If provided, it communicates with the DB listening at the endpoint. This is useful for testing with [Amazon Local DB] (http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html). 
end 

ENV変数を必ず更新してください。あなたはDynamoid宝石の代わりに、AWSに直接接続している場合それとも...

def client 
    @client ||= Aws::DynamoDB::Client.new(
    access_key_id: (ENV['AWS_ACCESS_KEY_ID'] || APP_CONFIG[:aws_access_key_id]), 
    secret_access_key: (ENV['AWS_SECRET_ACCESS_KEY'] || APP_CONFIG[:aws_secret_access_key]), 
    region: (ENV['AWS_REGION'] || 'us-east-1'), 
    endpoint: (ENV['DYNAMO_ENDPOINT'] || APP_CONFIG[:dynamo_endpoint]) 
) 
end 

に従うとhttp://docs.aws.amazon.com/AWSRubySDK/latest/AWS/DynamoDB.html

+0

申し訳ありません詳細情報については、この

client.query( table_name: table_name, select: 'COUNT', expression_attribute_values: { ':v1' => index }, key_condition_expression: 'user_id = :v1' ).count 

のようなクエリを実行します!私は 'ダイナモイド'宝石を使用していません。 –

+0

次に、 'client'メソッドを呼び出すことで2番目のオプションを使用できます – Selvamani

関連する問題