Reputation: 2074
In my scala application we are interacting with AWS. This is an internal company project but we still need to hide the 2 parameters which is a secret key and access key. Our code lives on github so I am not sure if there is any viable way to do it in scala? Or do we need to have them as export parameters on the server that the scala application picks up? If that is the case how would I do that?
val hadoopConf=sc.hadoopConfiguration;
hadoopConf.set("fs.s3.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
hadoopConf.set("fs.s3.awsAccessKeyId",myAccessKey)
hadoopConf.set("fs.s3.awsSecretAccessKey",mySecretKey)
Edit: We are running this app on a redhat physical server not on EC2. As it is not about scala mostly it seems, can anyone point me in a direction to help figure out this?
Upvotes: 0
Views: 328
Reputation: 10894
An approach would be to inject theses two values using environement variables
.
This could easily achieved using for example typesafe config
: https://github.com/typesafehub/config .
Therefore you create an application.conf
file:
AWS {
accessKey = {$AWS_ACCESS_KEY} // env variable AWS_ACCESS_KEY
secret = {$AWS_SECRET} // env variable AWS_SECRET
}
to use this in your application you then can access the values in this way:
import com.typesafe.config.ConfigFactory
conf = ConfigFactory.load()
val awsAccessKey = conf getString "AWS.accessKey"
val awsSecret = conf getString "AWS.secret"
A nice feature is that the code will throw a runtime exception when needed env variables are not set.
Upvotes: 3