Go utility for loading configuration parameters from AWS SSM (Parameter Store)

ssmconfig GoDoc Report card Go Cover

import "github.com/ianlopshire/go-ssm-config"

SSMConfig is a utility for loading configuration parameters from AWS SSM (Parameter Store) directly into a struct. This package is largely inspired by kelseyhightower/envconfig.

Motivation

This package was created to reduce the boilerplate code required when using Parameter Store to provide configuration to AWS Lambda functions. It should be suitable for additional applications.

Usage

Set some parameters in AWS Parameter Store:

Name Value Type Key ID
/exmaple_service/prod/debug false String -
/exmaple_service/prod/port 8080 String -
/exmaple_service/prod/user Ian String -
/exmaple_service/prod/rate 0.5 String -
/exmaple_service/prod/secret zOcZkAGB6aEjN7SAoVBT SecureString alias/aws/ssm

Write some code:

package main

import (
    "fmt"
    "log"
    "time"

    ssmconfig "github.com/ianlopshire/go-ssm-config"
)

type Config struct {
    Debug  bool    `ssm:"debug" default:"true"`
    Port   int     `ssm:"port"`
    User   string  `ssm:"user"`
    Rate   float32 `ssm:"rate"`
    Secret string  `ssm:"secret" required:"true"`
}

func main() {
    var c Config
    err := ssmconfig.Process("/example_service/prod/", &c)
    if err != nil {
        log.Fatal(err.Error())
    }
    
    format := "Debug: %v\nPort: %d\nUser: %s\nRate: %f\nSecret: %s\n"
    _, err = fmt.Printf(format, c.Debug, c.Port, c.User, c.Rate, c.Secret)
    if err != nil {
        log.Fatal(err.Error())
    }
}

Result:

Debug: false
Port: 8080
User: Ian
Rate: 0.500000
Secret: zOcZkAGB6aEjN7SAoVBT

Additional examples can be found in godoc.

Struct Tag Support

ssmconfig supports the use of struct tags to specify parameter name, default value, and required parameters.

type Config struct {
    Param         string `ssm:"param"`
    RequiredParam string `ssm:"required_param" required:"true"`
    DefaultParam  string `ssm:"default_param" default:"foobar"`
}

The ssm tag is used to lookup the parameter in Parameter Store. It is joined to the base path passed into Process(). If the ssm tag is missing ssmconfig will ignore the struct field.

The default tag is used to set the default value of a parameter. The default value will only be set if Parameter Store returns the parameter as invalid.

The required tag is used to mark a parameter as required. If Parameter Store returns a required parameter as invalid, ssmconfig will return an error.

The behavior of using the default and required tags on the same struct field is currently undefined.

Supported Struct Field Types

ssmconfig supports these struct field types:

  • string
  • int, int8, int16, int32, int64
  • bool
  • float32, float64

More supported types may be added in the future.

Licence

MIT

Owner
Ian Lopshire
Software engineer @timehop formerly @RedVentures. Open-source contributor, outdoors enthusiast, SpaceX fanboy. he/him.
Ian Lopshire
Similar Resources

Aws-cdk-go-examples - Example projects using the AWS CDK by Golang

aws-cdk-go-examples Example projects using the AWS CDK by Golang Useful commands

Nov 24, 2022

Support variable parameters task send worker

go-worker-pool Support variable parameters task send worker 调用方式 go get github.com/214200196/gwp/v1 import ( "fmt" "github.com/214200196/gwp/v1" "

Dec 16, 2021

Apple Store 预约助手

 Apple Store 预约助手

Apple Store 预约助手 本项目仅供学习使用 iPhone13系列 重构, 升级 fyne 至 2.0, 写起来的确比 1.0 舒服得多 azhan info 修改版本更多的意义在于___库存监控 2021.10.8_16:00pm, 完成了修复和测试 仅用于澳门iphone13预约 修改m

Apr 19, 2022

It is a package and command line application that provides you to store encrypted credentials/secrets in your repository.

sypher[ ⚠️ Work in progress] sypher provides you to store your credentials and secrets as encrypted in your repository. Usage Install the command line

Feb 23, 2022

Package figtree provides a multi-paradigm SDK for sophisticated configuration file access

Package figtree provides a multi-paradigm SDK for sophisticated configuration file access. Motivation Figtree syntax is based on classic key/value pai

Dec 31, 2021

TODO_GO: a simple todo API created in Golang with a minimum number of dependencies and configuration

TODO_GO: a simple todo API created in Golang with a minimum number of dependencies and configuration

TODO_GO TODO_GO is a simple todo API created in Golang with a minimum number of

Jan 1, 2022

AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Dec 31, 2022

Simple tool to search tagged resources between all AWS resouces

Welcome to Cloud Inventory Tags 👋 Simple tool to search tagged resources around all AWS Account Installation MacOS / OSX

Jan 26, 2022

Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises

Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises

AWS, Turn off my Account, please Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises Resource

Oct 25, 2022
Comments
  • Mention field name or SSM parameter when it's required and cannot be found

    Mention field name or SSM parameter when it's required and cannot be found

    When a parameter cannot be found in SSM you get a very simple error message: "ssmconfig: {} is required".

    Reproduction:

    type Config struct {
        ReqParam string `ssm:"req-param" required:"true"`
    }
    
    func main() {
        if err := ssmconfig.Process("/config/path/", config); err != nil {
            log.Fatal(err.Error()) // returns "ssmconfig: {} is required" when /config/path/req-param is not set
        }
    }
    

    I would like to see a field name and/or the path to the SSM parameter that should be set, something like: "ssmconfig: /config/path/req-param is required for ReqParam but could not be found"

  • [WIP] Decoding logic refactor

    [WIP] Decoding logic refactor

    This is a WIP PR to overhaul the way parameters are decoded. This should support additional types, nested structs, and much more.

    This also paves the way for possibly writing values back to Parameter Store

  • [Feature] Add nested struct/*struct and embedded struct

    [Feature] Add nested struct/*struct and embedded struct

    This PR adds support for nested structs, struct pointers, and embedded struct. Since this PR: https://github.com/ianlopshire/go-ssm-config/pull/2 looks to have gone silent, I went ahead and made the requested changes (documentation, tests, etc.)

A thin go client that interfaces with AWS SSM

go-ssm-aws A thin go client that interfaces with AWS SSM. Why this package? This

May 14, 2022
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022
Integrate AWS EKS Anywhere cluster with AWS Services
 Integrate AWS EKS Anywhere cluster with AWS Services

This article provides step-by-step instruction on integrating AWS EKS Anywhere with AWS Services so the applications running on customer data center can securely connect with these services.

Mar 6, 2022
Apis para la administracion de notifiaciones, utilizando servicios como AWS SNS y AWS SQS

notificacion_api Servicio para envío de notificaciónes por difusión en AWS SNS Especificaciones Técnicas Tecnologías Implementadas y Versiones Golang

Jan 7, 2022
A package for access aws service using AWS SDK for Golang

goaws ?? A package for access aws service using AWS SDK for Golang Advantage with goaws package Example for get user list IAM with AWS SDK for Golang

Nov 25, 2021
Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.
Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

tutor-pet API Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure. Macro architecture: Code architecture: Pre-Re

Aug 17, 2022
Feb 7, 2022
Aws-cognito-demo-go - Source code for AWS Cognito in Go

AWS Cognito Demo in Go Source code for YouTube series, AWS Cognito in Go - https

Dec 10, 2022
Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

May 7, 2022