title: Manage RDS access with AWS Secrets Manager
body: <p>I am currently working with Eclipse and the AWS Toolkit for Eclipse. My project already works and it is doing its job, which is to connect to an RDS instance and return JSON objects to API Gateway calls.</p>
  
  <p>I just got a new requirement, we are to use the service SecretsManager to authomatically rotate RDS configuration such as Users, passwords and so on.</p>
  
  <p>The problem is when I try to import classes such as <code>GetSecretValueResponse</code>, I get a <code>The import com.amazonaws.services.secretsmanager cannot be resolved</code>. When I explore the documentation and the SDK, there exists a <code>GetSecretValueRequest</code> but not a <code>GetSecretValueResponse</code>, so I am not being able to make sense on what should I do, nor I have found anything similar to an example I can study.</p>
  
  <p>The following code is what I am trying to implement and is given by Amazon itself (in the Secrets Manager page there is a button you can click to see how it would go with Java, in this case), and it is presented without any modification yet because as I said I do not know how to import several classes:</p>
  
  <pre><code>// Use this code snippet in your app.
  public static void getSecret() {
  String secretName = "secretName";
  String endpoint = "secretEndpoint";
  String region = "region";
  
  AwsClientBuilder.EndpointConfiguration config = new AwsClientBuilder.EndpointConfiguration(endpoint, region);
  AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard();
  clientBuilder.setEndpointConfiguration(config);
  AWSSecretsManager client = clientBuilder.build();
  
  String secret;
  ByteBuffer binarySecretData;
  GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder()
          .withSecretId(secretName)
          .build();
  GetSecretValueResponse getSecretValueResponse = null;
  try {
      getSecretValueResponse = client.getSecretValue(getSecretValueRequest);
  
  } catch(ResourceNotFoundException e) {
      System.out.println("The requested secret " + secretName + " was not found");
  } catch (InvalidRequestException e) {
      System.out.println("The request was invalid due to: " + e.getMessage());
  } catch (InvalidParameterException e) {
      System.out.println("The request had invalid params: " + e.getMessage());
  }
  
  if(getSecretValueResponse == null) {
      return;
  }
  
  // Decrypted secret using the associated KMS CMK
  // Depending on whether the secret was a string or binary, one of these fields will be populated
  if(getSecretValueResponse.getSecretString() != null) {
      secret = getSecretValueResponse.getSecretString();
  }
  else {
      binarySecretData = getSecretValueResponse.getSecretBinary();
  }
  
  // Your code goes here. 
  }
  </code></pre>