appconfig

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package appconfig retrieves configuration through the AWS AppConfig Data API.

New wraps an application-owned SDK Client with application and environment names in Config. Provider.Get uses a configuration profile name and GetOptions for session selectors, cache age and transforms.

Polling lifecycle

The provider manages configuration session tokens and serializes polling for each session. An unchanged service response retains the previous configuration. Reuse the provider across Lambda invocations so token and cache state survive. Provider.ClearCache invalidates local cached values.

For the local AppConfig Agent or Lambda extension HTTP interface, use the sibling appconfigagent package instead of this direct SDK adapter.

For usage and compatibility details, see the user guide.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAppConfig

func GetAppConfig(ctx context.Context, name string, options DefaultOptions) (any, error)

GetAppConfig uses the application and environment from the first successful initialization. Use separate providers for different applications or environments.

Types

type Client

type Client interface {
	StartConfigurationSession(context.Context, *sdk.StartConfigurationSessionInput, ...func(*sdk.Options)) (*sdk.StartConfigurationSessionOutput, error)
	GetLatestConfiguration(context.Context, *sdk.GetLatestConfigurationInput, ...func(*sdk.Options)) (*sdk.GetLatestConfigurationOutput, error)
}

type Config

type Config struct {
	Application, Environment string
	// Clock defaults to time.Now and controls both cache and token expiry.
	Clock func() time.Time
}

type DefaultOptions

type DefaultOptions struct {
	GetOptions
	Application, Environment string
}

type GetOptions

type GetOptions struct {
	parameters.Options
	SDKOptions *sdk.StartConfigurationSessionInput
}

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func New

func New(client Client, config Config) (*Provider, error)

func (*Provider) ClearCache

func (p *Provider) ClearCache()

ClearCache clears transformed values. Session tokens and last known configuration remain available because an unchanged AppConfig response has an empty body.

func (*Provider) Get

func (p *Provider) Get(ctx context.Context, name string, options GetOptions) (any, error)
Example

This example requires AWS credentials and an existing AppConfig deployment.

package main

import (
	"context"

	"github.com/aws/aws-sdk-go-v2/config"
	sdk "github.com/aws/aws-sdk-go-v2/service/appconfigdata"
	"github.com/rambow-cloud/powertools-lambda-go/parameters/appconfig"
)

func main() {
	ctx := context.Background()
	cfg, err := config.LoadDefaultConfig(ctx)
	if err != nil {
		panic(err)
	}
	provider, err := appconfig.New(sdk.NewFromConfig(cfg), appconfig.Config{
		Application: "example", Environment: "development",
	})
	if err != nil {
		panic(err)
	}
	value, err := provider.Get(ctx, "features", appconfig.GetOptions{})
	if err != nil {
		panic(err)
	}
	_ = value // Reuse the provider so session tokens survive warm invocations.
}

Jump to

Keyboard shortcuts

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