Search in sources :

Example 1 with GetParameterRequest

use of software.amazon.awssdk.services.ssm.model.GetParameterRequest in project aws-doc-sdk-examples by awsdocs.

the class GetParameter method getParaValue.

// snippet-start:[ssm.Java2.get_para_value.main]
public static void getParaValue(SsmClient ssmClient, String paraName) {
    try {
        GetParameterRequest parameterRequest = GetParameterRequest.builder().name(paraName).build();
        GetParameterResponse parameterResponse = ssmClient.getParameter(parameterRequest);
        System.out.println("The parameter value is " + parameterResponse.parameter().value());
    } catch (SsmException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetParameterRequest(software.amazon.awssdk.services.ssm.model.GetParameterRequest) GetParameterResponse(software.amazon.awssdk.services.ssm.model.GetParameterResponse) SsmException(software.amazon.awssdk.services.ssm.model.SsmException)

Example 2 with GetParameterRequest

use of software.amazon.awssdk.services.ssm.model.GetParameterRequest in project hippo by NHS-digital-website.

the class AwsRemoteSecrets method getRemoteValue.

@Override
public String getRemoteValue(String key) {
    AwsCredentialsProviderChain provider = AwsCredentialsProviderChain.of(StaticCredentialsProvider.create(AwsBasicCredentials.create(properties.getProperty("accessKey"), properties.getProperty("secretKey"))), // used by localhost
    EnvironmentVariableCredentialsProvider.create());
    try (SsmClient ssmClient = SsmClient.builder().credentialsProvider(provider).region(this.region).build()) {
        GetParameterRequest parameterRequest = GetParameterRequest.builder().name(key).withDecryption(true).build();
        GetParameterResponse parameterResponse = ssmClient.getParameter(parameterRequest);
        return parameterResponse.parameter().value();
    } catch (ParameterNotFoundException e) {
        log.warn(format("The remote parameter '%s' was not found", key));
        return null;
    }
}
Also used : GetParameterRequest(software.amazon.awssdk.services.ssm.model.GetParameterRequest) GetParameterResponse(software.amazon.awssdk.services.ssm.model.GetParameterResponse) ParameterNotFoundException(software.amazon.awssdk.services.ssm.model.ParameterNotFoundException) SsmClient(software.amazon.awssdk.services.ssm.SsmClient)

Aggregations

GetParameterRequest (software.amazon.awssdk.services.ssm.model.GetParameterRequest)2 GetParameterResponse (software.amazon.awssdk.services.ssm.model.GetParameterResponse)2 SsmClient (software.amazon.awssdk.services.ssm.SsmClient)1 ParameterNotFoundException (software.amazon.awssdk.services.ssm.model.ParameterNotFoundException)1 SsmException (software.amazon.awssdk.services.ssm.model.SsmException)1