AWS KMS API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 36: Line 36:


=Setting Explicit Credentials=
=Setting Explicit Credentials=
<syntaxhighlight lang='java'>
String masterKeyArn = "...";
       
AWSKMS kmsClient = AWSKMSClientBuilder.defaultClient();
DescribeKeyRequest req =
        new DescribeKeyRequest().
                withKeyId(masterKeyArn).
                withRequestCredentialsProvider(new AWSCredentialsProvider() {
                    @Override
                    public AWSCredentials getCredentials() {
                               
                        return new AWSCredentials() {
                                   
                            @Override
                            public String getAWSAccessKeyId() {
                                return "my-access-key-id";
                            }
                            @Override
                            public String getAWSSecretKey() {
                                return "my-secret-key-id";
                            }
                        };
                    }
                    @Override
                    public void refresh() {
                    }
                });
DescribeKeyResult res = kmsClient.describeKey(req);
</syntaxhighlight>


Also see: {{Internal|Setting_AWS_Credentials#Explicit_Credentials|Setting AWS Credentials}}
Also see: {{Internal|Setting_AWS_Credentials#Explicit_Credentials|Setting AWS Credentials}}

Revision as of 07:15, 30 November 2018

External

Internal

Overview

Dependencies

SKD 2

dependencies {
    // SDK 2
    implementation 'software.amazon.awssdk:kms:2.1.1'
}
http://repo1.maven.org/maven2/software/amazon/awssdk/kms/

SDK 1

dependencies {
    // SDK 1
    implementation 'com.amazonaws:aws-java-sdk-kms:1.11.458'
}
http://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-kms/

Setting Explicit Credentials

String masterKeyArn = "...";
        
AWSKMS kmsClient = AWSKMSClientBuilder.defaultClient();

DescribeKeyRequest req = 
        new DescribeKeyRequest().
                withKeyId(masterKeyArn).
                withRequestCredentialsProvider(new AWSCredentialsProvider() {
                     @Override
                     public AWSCredentials getCredentials() {
                                
                         return new AWSCredentials() {
                                    
                             @Override
                             public String getAWSAccessKeyId() {
                                 return "my-access-key-id";
                             }

                             @Override
                             public String getAWSSecretKey() {
                                 return "my-secret-key-id";
                             }
                         };
                     }
                     @Override
                     public void refresh() {
                     }
                 });

DescribeKeyResult res = kmsClient.describeKey(req);

Also see:

Setting AWS Credentials