Help us shape the future of Go! Take the 2026 Go Developer Survey

localstack

package
v0.22.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package localstack provides LocalStack integration for offline AWS testing

Index

Constants

View Source
const (
	// LocalStackEndpoint is the default LocalStack gateway endpoint
	LocalStackEndpoint = "http://localhost:4566"

	// LocalStackRegion is the default region for LocalStack testing
	LocalStackRegion = "us-west-2"

	// LocalStackAccessKey is the dummy access key for LocalStack
	LocalStackAccessKey = "test"

	// LocalStackSecretKey is the dummy secret key for LocalStack
	LocalStackSecretKey = "test"

	// EnvVarEnabled is the environment variable to enable LocalStack mode
	EnvVarEnabled = "PRISM_USE_LOCALSTACK"

	// EnvVarEndpoint allows overriding the LocalStack endpoint
	EnvVarEndpoint = "LOCALSTACK_ENDPOINT"

	// ConfigFilePath is the path to LocalStack resource configuration.
	// The init scripts write this to /var/lib/localstack/ inside the container,
	// which is volume-mounted to /tmp/localstack/ on the host.
	ConfigFilePath = "/tmp/localstack/prism-localstack-config.json"
)

LocalStack configuration constants

Variables

View Source
var RequiredServices = []string{
	"ec2",
	"s3",
	"ssm",
	"iam",
	"sts",
}

RequiredServices lists the AWS services that Prism requires in LocalStack Community. EFS is intentionally excluded: it requires LocalStack Pro (paid). Use HasEFSSupport() to determine whether EFS tests should run.

Functions

func GetEndpoint

func GetEndpoint() string

GetEndpoint returns the LocalStack endpoint to use Checks LOCALSTACK_ENDPOINT environment variable, falls back to default

func GetServiceStatus

func GetServiceStatus(ctx context.Context) (map[string]string, error)

GetServiceStatus returns the status of LocalStack services Returns a map of service names to their status ("available", "starting", "error", etc.)

func HasEFSSupport added in v0.7.7

func HasEFSSupport() bool

HasEFSSupport returns true if EFS is available in the current environment. Real AWS always supports EFS. LocalStack Community does not include EFS; set LOCALSTACK_EFS_SUPPORT=true to enable when using LocalStack Pro.

func IsHealthy

func IsHealthy(ctx context.Context) bool

IsHealthy checks if LocalStack is currently healthy

func IsLocalStackEnabled

func IsLocalStackEnabled() bool

IsLocalStackEnabled returns true if LocalStack mode is enabled via environment variable

func NewAWSConfig

func NewAWSConfig(ctx context.Context) (aws.Config, error)

NewAWSConfig creates an AWS configuration for LocalStack This configures the AWS SDK to use LocalStack endpoints and credentials

func NewAWSConfigWithProfile

func NewAWSConfigWithProfile(ctx context.Context, profile, region string) (aws.Config, error)

NewAWSConfigWithProfile creates an AWS configuration with custom profile/region support This is used by the Manager when profile options are provided

func ResetLocalStack

func ResetLocalStack(ctx context.Context) error

ResetLocalStack resets LocalStack state (requires LocalStack Pro for full reset) This is a best-effort operation for the free version

func VerifyRequiredServices

func VerifyRequiredServices(ctx context.Context) error

VerifyRequiredServices checks that all required services are available in LocalStack

func WaitForReady

func WaitForReady(ctx context.Context, timeout time.Duration) error

WaitForReady waits for LocalStack to be ready to accept requests This is useful in tests and CI environments where LocalStack may still be starting

Types

type Config

type Config struct {
	VPCID             string            `json:"vpc_id"`
	InternetGatewayID string            `json:"internet_gateway_id"`
	SubnetIDs         []string          `json:"subnet_ids"`
	SecurityGroupID   string            `json:"security_group_id"`
	AMIIDs            map[string]string `json:"ami_ids"`
	KeyPair           string            `json:"key_pair"`
	EFSFileSystemID   string            `json:"efs_file_system_id,omitempty"`
	EFSMountTargetIDs []string          `json:"efs_mount_target_ids,omitempty"`
}

Config holds LocalStack-specific resource configuration This is generated by the initialization scripts when LocalStack starts

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads LocalStack resource configuration from the config file This file is created by the initialization scripts and contains VPC IDs, AMI IDs, etc.

func (*Config) GetAMI

func (c *Config) GetAMI(key string) (string, error)

GetAMI returns the LocalStack AMI ID for a given OS distribution and architecture Example: GetAMI("ubuntu-22.04-x86_64") returns the mock Ubuntu 22.04 x86_64 AMI

func (*Config) GetDefaultSubnetID

func (c *Config) GetDefaultSubnetID() (string, error)

GetDefaultSubnetID returns the first available subnet ID This is useful for tests that don't care about specific subnet selection

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that all required LocalStack resources are configured

Jump to

Keyboard shortcuts

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