创建 Amazon KMS key - Amazon 适用于 Ruby 的 SDK
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建 Amazon KMS key

以下示例使用适用于 Ruby 的 Amazon SDK create_key 方法,该方法可实现 CreateKey 操作以创建 Amazon KMS keys。由于此示例仅加密少量数据,因此 KMS 密钥适合我们的目的。对于大量数据,请使用 KMS 密钥来加密数据加密密钥 (DEK)。

require "aws-sdk-kms" # v2: require 'aws-sdk' # Create a AWS KMS key. # As long we are only encrypting small amounts of data (4 KiB or less) directly, # a KMS key is fine for our purposes. # For larger amounts of data, # use the KMS key to encrypt a data encryption key (DEK). client = Aws::KMS::Client.new resp = client.create_key({ tags: [ { tag_key: "CreatedBy", tag_value: "ExampleUser" } ] }) puts resp.key_metadata.key_id

请参阅 GitHub 上的完整示例