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.
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([email protected],[email protected])))
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
}
Simply provide an implementation of the trait ValueWriter
. It's basically:
String => ParamResult[A]
,- where
ParamResult
is an alias toEither[InvalidParam[A], A]
, and InvalidParam
is simply a case class wrapping the name of the invalid parameter.