翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
サーバー側の暗号化 (SSE) の使用
AWS SDK for Java を使用して Amazon SQS キューにサーバー側の暗号化 (SSE) を追加できます。各キューは AWS Key Management Service (AWS KMS) KMS キーを使用してデータ暗号化キーを生成します。この例では AWS Amazon SQS のマネージド KMS キーを使用します。SSE および KMS キーのロールの使用における詳しい情報については、「保管中の暗号化」をご参照ください。
既存のキューに SSE を追加
既存のキューにサーバー側の暗号化を有効にする場合、SetQueueAttributes
メソッドで KmsMasterKeyId
属性を設定します。
以下のコード例では、AWS KMS key を Amazon SQS の AWS マネージド KMS キーとして設定します。また、この例では、AWS KMS key 再利用期間を 140 秒に設定します。
サンプルコードを実行する前に AWS の認証情報を設定したことをご確認ください。詳しい情報については、AWS SDK for Java 2.x デベロッパーガイドの開発用 AWS の認証情報およびリージョンのセットアップをご参照ください。
// Create an SqsClient for the specified Region. SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_1).build(); // Get the URL of your queue. String myQueueName = "my queue"; GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(myQueueName).build()); String queueUrl = getQueueUrlResponse.queueUrl(); // Create a hashmap for the attributes. Add the key alias and reuse period to the hashmap. HashMap<QueueAttributeName, String> attributes = new HashMap<QueueAttributeName, String>(); final String kmsMasterKeyAlias = "alias/aws/sqs"; // the alias of the AWS managed KMS key for Amazon SQS. attributes.put(QueueAttributeName.KMS_MASTER_KEY_ID, kmsMasterKeyAlias); attributes.put(QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS, "140"); // Create the SetQueueAttributesRequest. SetQueueAttributesRequest set_attrs_request = SetQueueAttributesRequest.builder() .queueUrl(queueUrl) .attributes(attributes) .build(); sqsClient.setQueueAttributes(set_attrs_request);
キューの SSE を無効化
既存のキューに対してサーバー側の暗号化を無効にする場合、SetQueueAttributes
メソッドを使用して KmsMasterKeyId
属性を空の文字列に設定します。
重要
null
は、KmsMasterKeyId
の有効な値ではありません。
SSE を使用してキューを作成
キュー作成時に SSE を有効にする場合、CreateQueue
API メソッドに KmsMasterKeyId
の属性を追加します。
以下の例では、SSE を有効にして新しいキューを作成する方法を示します。このキューは、Amazon SQS の AWS マネージド KMS キーを使用します。また、この例では、AWS KMS key 再利用期間を 160 秒に設定します。
サンプルコードを実行する前に AWS の認証情報を設定したことをご確認ください。詳しい情報については、AWS SDK for Java 2.x デベロッパーガイドの開発用 AWS の認証情報およびリージョンのセットアップをご参照ください。
// Create an SqsClient for the specified Region. SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_1).build(); // Create a hashmap for the attributes. Add the key alias and reuse period to the hashmap. HashMap<QueueAttributeName, String> attributes = new HashMap<QueueAttributeName, String>(); final String kmsMasterKeyAlias = "alias/aws/sqs"; // the alias of the AWS managed KMS key for Amazon SQS. attributes.put(QueueAttributeName.KMS_MASTER_KEY_ID, kmsMasterKeyAlias); attributes.put(QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS, "140"); // Add the attributes to the CreateQueueRequest. CreateQueueRequest createQueueRequest = CreateQueueRequest.builder() .queueName(queueName) .attributes(attributes) .build(); sqsClient.createQueue(createQueueRequest);
SSE 属性を取得
キュー属性の取得の詳細については、Amazon Simple キューサービス API リファレンスの例をご参照ください。
特定のキューの KMS キー ID またはデータキーの再利用期間を取得する場合、GetQueueAttributes
メソッドを実行して KmsMasterKeyId
および KmsDataKeyReusePeriodSeconds
値を取得します。