使用 Scala 访问 SecureString SSM 参数

Accessing SecureString SSM parameters with Scala

我在 Glue 中使用 Scala 脚本来访问具有依赖库的第三方供应商。可以看到the template I'm working off here

此解决方案运行良好,但使用以明文形式存储的参数运行。我想将它们移动到 AWS SSM 并将它们存储为 SecureString。为此,我认为该函数必须从 KMS 中提取 CMK,然后提取 SecureString 并使用 CMK 对其进行解密。

我在互联网上四处寻找代码示例,试图找到一些简单的代码示例,例如从 Scala 中提取 SSM 参数,但我什么也没找到。我才刚刚开始使用这门语言,对它的结构不是很熟悉,是否期望 aws-java 库也能在 Scala 中用于此类操作?我已经试过了,但在 Glue 中出现编译错误。举个例子

import software.amazon.awscdk.services.ssm.StringParameter;

  
object SfdcExtractData {  
  def main(sysArgs: Array[String]) {  
    print("starting")
    
    String secureStringToken = StringParameter.valueForSecureStringParameter(this, "my-secure-parameter-name", 1);   // must specify version

给出一个编译错误,虽然 aws glue 不能很好地告诉我问题是什么。

感谢您的宝贵时间!如果您有任何代码示例、见解或资源,请告诉我。我的工作是 运行 Scala 2 on Spark 2.4

能够使用以下代码片段做到这一点

import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult

    // create a client AWSSimpleSystemsManagementClient object
    val client = new AWSSimpleSystemsManagementClient()

    // Create a GetParameterRequest object, which send the actual request
    val req = new GetParameterRequest()

    // set the name of the parameter in the object. 
    req.setName("test")
    // Only needed if the parameter is a secureString encrypted with the default kms key. If you're using a CMK you need to add the glue user as a key user. To do so, navigate to KMS console --> Customer Managed Keys --> Click on KMS key used for encryption --> Under Key policies --> Key user --> Add ( Add the Glue role )
    req.setWithDecryption(true)


    // call the getParameter() function on the object
    val param = client.getParameter(req)

记得也给你的胶水角色 iam ssm 权限!