ServerSideEncryptionByDefault

ServerSideEncryptionByDefault

我一直找不到要允许我在S3中创建KMS加密存储桶的调用(使用Java AWS开发工具包)。

是否存在这种方法?如果是这样,我在哪里可以找到示例/文档?

最佳答案

我找到了答案。我使用的AWS Java SDK版本还不够新,无法使用该方法。

这是操作方法:

    Bucket bucket =  amazonS3Client.createBucket( bucketName );
    ServerSideEncryptionRule serverSideEncryptionRule = new ServerSideEncryptionRule();

    ServerSideEncryptionByDefault serverSideEncryptionByDefault = new ServerSideEncryptionByDefault();
    serverSideEncryptionByDefault.setKMSMasterKeyID( "xxxxxxxxx-xxx-xxxxx-xxxx-xxxxx-xxxx-xxxxxxx" );
    serverSideEncryptionByDefault.setSSEAlgorithm( SSEAlgorithm.KMS.getAlgorithm() );

    serverSideEncryptionRule.setApplyServerSideEncryptionByDefault( serverSideEncryptionByDefault );

    SetBucketEncryptionRequest setBucketEncryptionRequest = new SetBucketEncryptionRequest();
    setBucketEncryptionRequest.setBucketName( bucket.getName() );

    ServerSideEncryptionConfiguration serverSideEncryptionConfiguration = new ServerSideEncryptionConfiguration();

    ArrayList< ServerSideEncryptionRule > serverSideEncryptionRules = new ArrayList<>();
    serverSideEncryptionRules.add( serverSideEncryptionRule );
    serverSideEncryptionConfiguration.setRules( serverSideEncryptionRules );

    setBucketEncryptionRequest.setServerSideEncryptionConfiguration( serverSideEncryptionConfiguration );

    amazonS3Client.setBucketEncryption( setBucketEncryptionRequest );

07-26 03:52