2016-06-19 14 views
0

私はDynamoDBテーブルにアクセスする必要のあるアプリケーションを持っています。各作業者は、データベースとの接続を独自に確立します。Spark Workerの環境変数にアクセス

AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYの両方をマスターとワーカーの両方に追加しましたspark-env.shファイル。また、変数がエクスポートされていることを確認するためにshを使用してファイルを実行しました。

コードが実行されると、私は常にエラーを取得:

Caused by: com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain 
    at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:131) 
    at com.amazonaws.http.AmazonHttpClient.getCredentialsFromContext(AmazonHttpClient.java:774) 
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:800) 
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:695) 
    at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:447) 
    at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:409) 
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:358) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2051) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2021) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.describeTable(AmazonDynamoDBClient.java:1299) 
    at com.amazon.titan.diskstorage.dynamodb.DynamoDBDelegate.describeTable(DynamoDBDelegate.java:635) 
    ... 27 more 

AWS SDKは、それらがエクスポートしているにもかかわらず、資格情報をロードするために失敗したようです。どんなタイプのソリューションを試すべきですか?

+1

コードで明示的に設定できますか? http://stackoverflow.com/questions/33475931/spark-streaming-checkpoint-to-amazon-s3 – Knight71

+0

@ Knight71、私は危険なことはできませんでしたか? –

答えて

2

SparkConfで​​メソッドを使用できます。例えば

/** 
    * Set an environment variable to be used when launching executors for this application. 
    * These variables are stored as properties of the form spark.executorEnv.VAR_NAME 
    * (for example spark.executorEnv.PATH) but this method makes them easier to set. 
    */ 
    def setExecutorEnv(variable: String, value: String): SparkConf = { 
    set("spark.executorEnv." + variable, value) 
    } 

また

/** 
    * Set multiple environment variables to be used when launching executors. 
    * These variables are stored as properties of the form spark.executorEnv.VAR_NAME 
    * (for example spark.executorEnv.PATH) but this method makes them easier to set. 
    */ 
    def setExecutorEnv(variables: Seq[(String, String)]): SparkConf = { 
    for ((k, v) <- variables) { 
     setExecutorEnv(k, v) 
    } 
    this 
    } 

あなたは、このようなJavaシステムプロパティの設定など、他のオプションを検討するかもしれない:SparkConfはそれらを自動的にピックアップします。

+0

を実行し、以下のようなエグゼキュータでその値を読み取ります:::::: val property_value = System.getEnv( "property_key") – Suresh