我正在尝试在 Scala 项目中实施 AWS Secrets Manager,有人尝试过吗?
我已经像这样在 build.sbt 上的项目中添加了依赖项
libraryDependencies ++= Seq(
"com.databricks" %% "spark-avro" % "4.0.0",
"com.amazonaws" % "aws-java-sdk-core" % "1.11.569",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.569",
"com.amazonaws" % "aws-java-sdk-secretsmanager" % "1.11.569",
"com.typesafe" % "config" % "1.3.4",
"org.apache.spark" %% "spark-core" % "2.3.0" % "provided",
"org.apache.spark" %% "spark-sql" % "2.3.0" % "provided",
"org.apache.spark" %% "spark-hadoop-cloud" % "2.3.2.3.1.0.6-1" % "provided",
"org.apache.hadoop" % "hadoop-common" % "3.1.1.3.0.2.0-50" % "provided",
"com.github.gphat" %% "datadog-scala" % "1.1.3" exclude ("org.json4s", "json4s-jackson") exclude ("org.json4s", "json4s-native"),
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.mockito" % "mockito-core" % "2.27.0" % "test",
"com.github.tomakehurst" % "wiremock-jre8" % "2.23.2" % "test",
"org.glassfish.jersey.core" % "jersey-common" % "2.22.2" % "test",
"org.glassfish.jersey.core" % "jersey-server" % "2.22.2" % "test",
"org.glassfish.jersey.core" % "jersey-client" % "2.22.2" % "test"
)
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) =>
xs map { _.toLowerCase } match {
case "manifest.mf" :: Nil | "index.list" :: Nil | "dependencies" :: Nil =>
MergeStrategy.discard
case ps @ x :: xs if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
MergeStrategy.discard
case "plexus" :: xs =>
MergeStrategy.discard
case "services" :: xs =>
MergeStrategy.filterDistinctLines
case "spring.com.conekta.schemas" :: Nil | "spring.handlers" :: Nil =>
MergeStrategy.filterDistinctLines
case _ => MergeStrategy.first
}
我的实现是这样的
def getSecrets: Map[String,String] ={
val secretName = "***********************"
val endpoint = "secretsmanager.us-east-1.amazonaws.com"
val config = new AwsClientBuilder.EndpointConfiguration(endpoint, Regions.US_EAST_1.getName)
val clientBuilder = AWSSecretsManagerClientBuilder.standard()
clientBuilder.setEndpointConfiguration(config)
val client = clientBuilder.build()
val getSecretValueRequest = new GetSecretValueRequest().withSecretId(secretName).withVersionStage("AWSCURRENT")
val getSecretValueResult = client.getSecretValue(getSecretValueRequest)
val secret = getSecretValueResult.getSecretString
implicit val formats = DefaultFormats
parse(secret).extract[Map[String, String]]
}
它在本地工作,但是当我将我的 jar 上传到我正在处理的服务器时,我收到了这个错误:
java.lang.NoSuchMethodError: com.amazonaws.client.AwsSyncClientParams.getAdvancedConfig()Lcom/amazonaws/client/builder/AdvancedConfig;
at com.amazonaws.services.secretsmanager.AWSSecretsManagerClient.<init>(AWSSecretsManagerClient.java:213)
at com.amazonaws.services.secretsmanager.AWSSecretsManagerClient.<init>(AWSSecretsManagerClient.java:197)
at com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder.build(AWSSecretsManagerClientBuilder.java:61)
at com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder.build(AWSSecretsManagerClientBuilder.java:27)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.conekta.helpers.SecretManager.getSecrets(SecretManager.scala:21)
有没有人在 sbt 项目上成功实施了 aws secret manager 任何帮助都会非常有用。谢谢。