【问题标题】:Can a SSE:KMS Key ID be specified when writing to S3 in an AWS Glue Job?在 AWS Glue 作业中写入 S3 时是否可以指定 SSE:KMS 密钥 ID?
【发布时间】:2018-03-21 11:30:37
【问题描述】:

如果您按照 AWS Glue 添加作业向导创建脚本以将 parquet 文件写入 S3,您最终会生成类似这样的代码。

datasink4 = glueContext.write_dynamic_frame.from_options(
    frame=dropnullfields3,
    connection_type="s3",
    connection_options={"path": "s3://my-s3-bucket/datafile.parquet"},
    format="parquet",
    transformation_ctx="datasink4",
)

是否可以指定 KMS 密钥,以便在存储桶中加密数据?

【问题讨论】:

    标签: amazon-web-services aws-glue amazon-kms


    【解决方案1】:

    粘合 scala 作业

    val spark: SparkContext = new SparkContext()
    val glueContext: GlueContext = new GlueContext(spark)
    spark.hadoopConfiguration.set("fs.s3.enableServerSideEncryption", "true")
    spark.hadoopConfiguration.set("fs.s3.serverSideEncryption.kms.keyId", args("ENCRYPTION_KEY"))
    

    我认为 Python 的语法应该不同,但想法相同

    【讨论】:

      【解决方案2】:

      要使用 PySpark 拼出答案,您可以这样做

      from pyspark.conf import SparkConf
      [...]
      spark_conf = SparkConf().setAll([
        ("spark.hadoop.fs.s3.enableServerSideEncryption", "true"),
        ("spark.hadoop.fs.s3.serverSideEncryption.kms.keyId", "<Your Key ID>")
      ])
      sc = SparkContext(conf=spark_conf)
      

      注意 spark.hadoop 前缀 - 或(更丑但更短)

      sc._jsc.hadoopConfiguration().set("fs.s3.enableServerSideEncryption", "true")
      sc._jsc.hadoopConfiguration().set("fs.s3.serverSideEncryption.kms.keyId", "<Your Key ID>")
      

      sc 是您当前的 SparkContext。

      【讨论】:

        【解决方案3】:

        这不是必需的。也许是第一次提出问题的时候,但同样可以通过创建安全配置并将其与胶水作业相关联来实现。只要记住在你的脚本中有这个,否则它不会这样做:

        job = Job(glueContext) 
        job.init(args['JOB_NAME'], args)
        

        https://docs.aws.amazon.com/glue/latest/dg/encryption-security-configuration.html https://docs.aws.amazon.com/glue/latest/dg/set-up-encryption.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-02-07
          • 1970-01-01
          • 2021-05-01
          • 1970-01-01
          • 1970-01-01
          • 2020-05-20
          • 2020-06-15
          • 2022-01-09
          相关资源
          最近更新 更多