lambdassmmiddleware

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 11 Imported by: 0

README

lambdassmmiddlware

AWS Lambda middleware of ssm parameters middleware for Golang don't need any extensions to use this middleware, get parameters using the SDK.

package main

import (
	"context"
	"encoding/json"
	"log"
	"os"
	"strings"
	"time"

	"github.com/aws/aws-lambda-go/lambda"
	"github.com/mashiike/lambdassmmiddleware"
)

type ssmContextKey string

func main() {
	handler, err := lambdassmmiddleware.Wrap(
		&lambdassmmiddleware.Config{
			Paths:          strings.Split(os.Getenv("SSMPATHS"), ","),
			Names:          strings.Split(os.Getenv("SSMNAMES"), ","),
			ContextKeyFunc: func(key string) interface{} { return ssmContextKey(key) },
			EnvPrefix:      "SSM_",
			CacheTTL:       24 * time.Hour,
			SetEnv:         true,
		},
		func(ctx context.Context, payload json.RawMessage) (interface{}, error) {
			return map[string]interface{}{
				"env_hoge": os.Getenv("SSM_HOGE"),
				"env_foo":  os.Getenv("SSM_FOO"),
				"env_bar":  os.Getenv("SSM_BAR"),
				"hoge":     ctx.Value(ssmContextKey("/lambdassmmiddleware/paths/hoge")),
				"foo":      ctx.Value(ssmContextKey("/lambdassmmiddleware/foo")),
				"bar":      ctx.Value(ssmContextKey("/lambdassmmiddleware/bar")),
				"tora":     ctx.Value(ssmContextKey("/lambdassmmiddleware/tora")),
			}, nil
		},
	)
	if err != nil {
		log.Fatalln(err)
	}
	lambda.Start(handler)
}

see deteils _example/

$ make lambroll/invoke 
lambroll invoke
2023/03/28 17:15:38 [info] lambroll v0.14.2 with function.json
Enter JSON payloads for the invoking function into STDIN. (Type Ctrl-D to close.)
{}
{"bar":"bar values","env_bar":"bar values","env_foo":"foo values","env_hoge":"hoge values","foo":"foo values","hoge":"hoge values","tora":null}
2023/03/28 17:15:44 [info] StatusCode:200
2023/03/28 17:15:44 [info] ExecutionVersion:$LATEST

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func Wrap

func Wrap(cfg *Config, handler interface{}) (lambda.Handler, error)

Types

type Config

type Config struct {
	Names          []string
	Paths          []string
	Client         *ssm.Client
	ContextKeyFunc func(key string) interface{}
	SetEnv         bool
	EnvPrefix      string

	CacheTTL time.Duration
	// contains filtered or unexported fields
}

func (*Config) WithClient

func (cfg *Config) WithClient(client *ssm.Client) *Config

func (*Config) WithDecryption

func (cfg *Config) WithDecryption(value bool) *Config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL