来自AWS Secret Manager的AWS Glue连接

时间:2019-07-02 19:55:57

标签: aws-glue aws-glue-data-catalog

在AWS Glue中创建JDBC连接时,有什么方法可以从AWS Secret Manager中获取密码,而不是手动对其进行硬编码吗?

2 个答案:

答案 0 :(得分:0)

我必须在当前项目中执行此操作才能连接到Cassandra数据库,这是我的工作方式。.我将实际的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()
}

答案 1 :(得分:0)