public static String getSecret()

in src/main/java/com/lambdajavablockchain/SecretsManagerUtil.java [56:83]


    public static String getSecret(String secretName) throws SecretNotFoundException {
        // Create a Secrets Manager client
        AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard()
                .withRegion(AMBConfig.REGION)
                .build();

        GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest()
                .withSecretId(secretName);
        GetSecretValueResult getSecretValueResult = null;

        try {
            getSecretValueResult = client.getSecretValue(getSecretValueRequest);
        } catch (DecryptionFailureException | InvalidParameterException
                | InvalidRequestException | InternalServiceErrorException e) {
            log.warn("Unable to retrieve secret " + secretName);
            throw new SecretNotFoundException("Unable to retrieve secret", e);
        } catch (ResourceNotFoundException e) {
            log.warn("Secret not found in Secrets Manager " + secretName);
            throw new SecretNotFoundException("Secret not found in Secrets Manager", e);
        }

        if (getSecretValueResult.getSecretString() != null) {
            return getSecretValueResult.getSecretString();
        } else {
            return new String(Base64.getDecoder()
                    .decode(getSecretValueResult.getSecretBinary()).array());
        }
    }