在 AWS Glue 中创建 JDBC 连接时,有没有办法从 AWS 机密管理器获取密码,而不是手动硬编码?
问问题
3004 次
2 回答
1
我必须在我当前的项目中这样做才能连接到 Cassandra DB,这就是我的做法。我将实际的 secrets_key 作为工作参数传递 --SECRETS_KEY my/secrets/key
// here's method to pull from secrets manager
def retrieveSecrets(secrets_key: String) :Map[String,String] = {
val awsSecretsClient = AWSSecretsManagerClientBuilder.defaultClient()
val getSecretValueRequest = new GetSecretValueRequest().withSecretId(secrets_key)
val secretValue = awsSecretsClient.getSecretValue(getSecretValueRequest)
val secretJson = secretValue.getSecretString()
val result = JSON.parseFull(secretJson)
val jsonMap:Map[String,String] = result.get.asInstanceOf[Map[String, String]]
return jsonMap
}
// main script where I invoke this call BEFORE the glue stuff is setup..
def main(sysArgs: Array[String]) {
println("***** RETRIEVING Secrets from SecretsManager ****** ")
// pull secrets from map
val secretsMap = retrieveSecrets(secrets_key)
val host_names = secretsMap.get("HOST_NAMES").get
val user_id = secretsMap.get("USER_ID").get
val password = secretsMap.get("PASSWORD").get
// I needed to configure this BEFORE we create the spark Context
val conf = setupCassandraConfiguration(host_names, user_id, password)
val sparkContext: SparkContext = new SparkContext(conf)
// now create the glue context using the spark context created with the cassandra options attached
val glueContext: GlueContext = new GlueContext(sparkContext)
Job.init(args("JOB_NAME"), glueContext, args.asJava)
val spark = glueContext.getSparkSession
println("***** ALL contexts created - starting loading tables ****** ")
import spark.implicits._
val myDF = spark.read.format("org.apache.spark.sql.cassandra").options(Map( "table" -> "my_table", "keyspace" -> "my_keyspace" )).load()
}
于 2019-07-09T13:09:45.307 回答
0
在此处查看此示例-他们使用了秘密管理器 https://aws.amazon.com/blogs/big-data/use-aws-glue-to-run-etl-jobs-against-non-native-jdbc-data-sources /
于 2020-10-06T21:30:48.680 回答