java.lang.Object
software.amazon.lambda.powertools.parameters.BaseProvider
software.amazon.lambda.powertools.parameters.ssm.SSMProvider
All Implemented Interfaces:
ParamProvider

public class SSMProvider extends BaseProvider
AWS System Manager Parameter Store Provider

Samples:
     SSMProvider provider = SSMProvider.builder().build();

     String value = provider.get("key");
     System.out.println(value);
     >>> "value"

     // Get a value and cache it for 30 seconds (all others values will now be cached for 30 seconds)
     String value = provider.defaultMaxAge(30, ChronoUnit.SECONDS).get("key");

     // Get a value and cache it for 1 minute (all others values are cached for 5 seconds by default)
     String value = provider.withMaxAge(1, ChronoUnit.MINUTES).get("key");

     // Get a base64 encoded value, decoded into a String, and store it in the cache
     String value = provider.withTransformation(Transformer.base64).get("key");

     // Get a json value, transform it into an Object, and store it in the cache
     TargetObject = provider.withTransformation(Transformer.json).get("key", TargetObject.class);

     // Get a decrypted value, and store it in the cache
     String value = provider.withDecryption().get("key");

     // Get multiple parameter values starting with the same path
     Mapinvalid input: '<'String, String> params = provider.getMultiple("/path/to/paramters");
     >>> /path/to/parameters/key1 -> value1
     >>> /path/to/parameters/key2 -> value2

     // Get multiple parameter values starting with the same path and recursively
     Mapinvalid input: '<'String, String> params = provider.recursive().getMultiple("/path/to/paramters");
     >>> /path/to/parameters/key1 -> value1
     >>> /path/to/parameters/key2 -> value2
     >>> /path/to/parameters/others/key3 -> value3
 
  • Method Details

    • builder

      public static SSMProviderBuilder builder()
      Create a builder that can be used to configure and create a SSMProvider.
      Returns:
      a new instance of SSMProviderBuilder
    • create

      public static SSMProvider create()
      Create a SSMProvider with all default settings.
    • getValue

      public String getValue(String key)
      Retrieve the parameter value from the AWS System Manager Parameter Store.
      Specified by:
      getValue in class BaseProvider
      Parameters:
      key - key of the parameter
      Returns:
      the value of the parameter identified by the key
    • withDecryption

      public SSMProvider withDecryption()
      Tells System Manager Parameter Store to decrypt the parameter value.
      By default, parameter values are not decrypted.
      Valid both for get and getMultiple.
      Returns:
      the provider itself in order to chain calls (eg.
      provider.withDecryption().get("key")
      ).
    • recursive

      public SSMProvider recursive()
      Tells System Manager Parameter Store to retrieve all parameters starting with a path (all levels)
      Only used with BaseProvider.getMultiple(String).
      Returns:
      the provider itself in order to chain calls (eg.
      provider.recursive().getMultiple("key")
      ).
    • getMultipleValues

      protected Map<String,String> getMultipleValues(String path)
      Retrieve multiple parameter values from AWS System Manager Parameter Store.
      Retrieve all parameters starting with the path provided in parameter.
      eg. getMultiple("/foo/bar") will retrieve /foo/bar/baz, foo/bar/biz
      Using recursive(), getMultiple("/foo/bar") will retrieve /foo/bar/baz, foo/bar/biz and foo/bar/buz/boz
      Cache all values with the 'path' as the key and also individually to be able to BaseProvider.get(String) a single value later
      Does not support transformation.
      Specified by:
      getMultipleValues in class BaseProvider
      Parameters:
      path - path of the parameter
      Returns:
      a map containing parameters keys and values. The key is a subpart of the path
      eg. getMultiple("/foo/bar") will retrieve [key="baz", value="valuebaz"] for parameter "/foo/bar/baz"
    • resetToDefaults

      protected void resetToDefaults()
      Overrides:
      resetToDefaults in class BaseProvider