AWS KMS API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:


* [[Amazon_KMS#AWS_KMS_API|Amazon KMS]]
* [[Amazon_KMS#AWS_KMS_API|Amazon KMS]]
* [[AWS_SDK_for_Java#Overview|AWS SDK for Java]]
* [[AWS_SDK_for_Java_Version_2#Component_APIs|AWS SDK for Java Version 2]]


=Overview=
=Overview=
Line 14: Line 14:


==SKD 2==
==SKD 2==
<font color=darkgray>TODO: Gradle dependencies for ASW SDK for Java 2 look differently: https://kb.novaordis.com/index.php/AWS_SDK_for_Java_Version_2#Gradle_Project</font>


<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
Line 25: Line 27:


==SDK 1==
==SDK 1==
 
<font color=darkgray>TODO: Gradle dependencies for ASW SDK for Java 1 look differently: https://kb.novaordis.com/index.php/AWS_SDK_for_Java_Version_1#Gradle_Project</font>
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
dependencies {
dependencies {
Line 34: Line 36:


{{External|http://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-kms/}}
{{External|http://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-kms/}}
=Playground Example=
{{External|[https://github.com/ovidiuf/playground/blob/master/amazon/kms/01-simplest/src/main/java/playground/amazon/kms/KMSExamples.java KMS Example in Playground]}}


=Setting Explicit Credentials=
=Setting Explicit Credentials=


<syntaxhighlight lang='java'>
<syntaxhighlight lang='java'>
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClientBuilder;
import com.amazonaws.services.kms.model.DescribeKeyRequest;
import com.amazonaws.services.kms.model.DescribeKeyResult;
String masterKeyArn = "...";
String masterKeyArn = "...";
          
          

Latest revision as of 05:53, 3 October 2021

External

Internal

Overview

Dependencies

SKD 2

TODO: Gradle dependencies for ASW SDK for Java 2 look differently: https://kb.novaordis.com/index.php/AWS_SDK_for_Java_Version_2#Gradle_Project

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

SDK 1

TODO: Gradle dependencies for ASW SDK for Java 1 look differently: https://kb.novaordis.com/index.php/AWS_SDK_for_Java_Version_1#Gradle_Project

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

Playground Example

KMS Example in Playground

Setting Explicit Credentials

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClientBuilder;
import com.amazonaws.services.kms.model.DescribeKeyRequest;
import com.amazonaws.services.kms.model.DescribeKeyResult;

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