Menu
AWS Key Management Service
Developer Guide

Creating a Client

Before you can program to the AWS Key Management Service, you must create a client, as shown by the following example. The client object, kms, is used throughout all of the code in the sections that follow.

package com.amazon.kms;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClient;
import com.amazonaws.services.kms.model.*;

public class kmsSDKExample {

    private final AWSKMSClient kms;

    public kmsSDKExample() {
        kms = getClient();
    }

    public static void main(String[] args) {
        new kmsSDKExample();
    }

    private AWSKMS getClient() {
        final AWSCredentials creds;

        AWSKMSClient kms = new AWSKMSClient(creds);

        // Use the endpoint that corresponds to your region. This example uses the US West (Oregon)
        // region. For more information, see http://amzn.to/1mKTMmG (docs.aws.amazon.com)
        kms.setEndpoint("https://kms.us-west-2.amazonaws.com");

        return kms;
    }
}