Skip to content

Library for reading data from AWS' Parameter Store

License

Notifications You must be signed in to change notification settings

kdrakon/scala-aws-params-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scala AWS Params Reader

Build Status Maven Central

What?

A library that lets you read data from AWS' EC2 Systems Manager Parameter Store in a Scala-friendly way. It supports reading data in AWS' three formats - String, StringList, and SecureString - implicitly into Scala types.

Huh?

Example

  
package io.policarp.scala

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder
import io.policarp.scala.aws.params.reader.ParamReader
import io.policarp.scala.aws.params.reader.ListWriter._

object Test extends App {

  val client = AWSSimpleSystemsManagementClientBuilder.standard().withCredentials(new DefaultAWSCredentialsProviderChain()).build()
  val params = ParamReader(client)
  
  println(params.read[Long]("length"))
  // Right(42)
  
  println(params.readList[Long]("length"))
  // Left(InvalidParam(length)) because 'length' is actually a single parameter
  
  println(params.readList[String]("names"))
  // Right(List(Grayson,Jemma)))
  
  println(params.readList[String]("emails", listSeparator = Semicolon))
  // Right(List(alice@somemail.com,bob@anothermail.com)))  
  
  println(params.readSecure[String]("mysecret"))
  // Right(hunter2), where data is decrypted using Amazon's Key Management Service if your credentials allow for it
  
  println(params.readSecure[String]("yoursecret"))
  // Left(InvalidParam(yoursecret)) because 'yoursecret' does not exist OR your credentials don't allow for reading
}

Other Types?

Simply provide an implementation of the trait ValueWriter. It's basically:

  • String => ParamResult[A],
  • where ParamResult is an alias to Either[InvalidParam[A], A], and
  • InvalidParam is simply a case class wrapping the name of the invalid parameter.