Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing AWS parameter store values with custom KMS key

I am trying to read AWS parameters from the parameter store using java, i have created the parameters using a custom encryption key. I dont see a sample code in the internet where its using a custom KMS key , the below is the code i currently have which is working (here we are usingthe default KMS key).

AWSSimpleSystemsManagement client= AWSSimpleSystemsManagementClientBuilder.defaultClient();
    GetParametersRequest request= new GetParametersRequest();
    request.withNames("test.username","test.password")
           .setWithDecryption(true);

This will give the results with default KMS key Does anyone know how to handle this if we have a custom KMS key

like image 983
Java Programmer Avatar asked Apr 04 '17 15:04

Java Programmer


1 Answers

just in case, if somebody looking for this (with Default encryption Key)

protected Parameter getParameterFromSSMByName(String parameterKey)
  {
    AWSCredentialsProvider credentials = InstanceProfileCredentialsProvider.getInstance();
    AWSSimpleSystemsManagement simpleSystemsManagementClient = (AWSSimpleSystemsManagement)((AWSSimpleSystemsManagementClientBuilder)((AWSSimpleSystemsManagementClientBuilder)AWSSimpleSystemsManagementClientBuilder.standard().withCredentials(credentials)).withRegion("us-east-1")).build();
    GetParameterRequest parameterRequest = new GetParameterRequest();
    parameterRequest.withName(parameterKey).setWithDecryption(Boolean.valueOf(true));
    GetParameterResult parameterResult = simpleSystemsManagementClient.getParameter(parameterRequest);
    return parameterResult.getParameter();
  }
like image 128
Extreme Avatar answered Oct 11 '22 04:10

Extreme