localstack package - github.com/elgohr/go-localstack - Go Packages (original) (raw)
- func WithClientFromEnv() (InstanceOption, error)
- func WithClientFromEnvCtx(ctx context.Context) (InstanceOption, error)
- func WithLabels(labels map[string]string) InstanceOption
- func WithLogger(logger *logrus.Logger) InstanceOption
- func WithTimeout(timeout time.Duration) InstanceOption
- func WithVersion(version string) InstanceOption
This section is empty.
var ( FixedPort = Service{Name: "all", Port: "4566/tcp"}
CloudFormation = [Service](#Service){Name: "cloudformation", Port: "4581/tcp"}
CloudWatch = [Service](#Service){Name: "cloudwatch", Port: "4582/tcp"}
CloudWatchLogs = [Service](#Service){Name: "cloudwatchlogs", Port: "4586/tcp"}
CloudWatchEvents = [Service](#Service){Name: "cloudwatchevents", Port: "4587/tcp"}
DynamoDB = [Service](#Service){Name: "dynamoDB", Port: "4569/tcp"}
DynamoDBStreams = [Service](#Service){Name: "dynamoDBStreams", Port: "4570/tcp"}
EC2 = [Service](#Service){Name: "ec2", Port: "4597/tcp"}
ES = [Service](#Service){Name: "es", Port: "4578/tcp"}
Firehose = [Service](#Service){Name: "firehose", Port: "4573/tcp"}
IAM = [Service](#Service){Name: "iam", Port: "4593/tcp"}
Kinesis = [Service](#Service){Name: "kinesis", Port: "4568/tcp"}
Lambda = [Service](#Service){Name: "lambda", Port: "4574/tcp"}
Redshift = [Service](#Service){Name: "redshift", Port: "4577/tcp"}
Route53 = [Service](#Service){Name: "route53", Port: "4580/tcp"}
S3 = [Service](#Service){Name: "s3", Port: "4572/tcp"}
SecretsManager = [Service](#Service){Name: "secretsmanager", Port: "4584/tcp"}
SES = [Service](#Service){Name: "ses", Port: "4579/tcp"}
SNS = [Service](#Service){Name: "sns", Port: "4575/tcp"}
SQS = [Service](#Service){Name: "sqs", Port: "4576/tcp"}
SSM = [Service](#Service){Name: "ssm", Port: "4583/tcp"}
STS = [Service](#Service){Name: "sts", Port: "4592/tcp"}
StepFunctions = [Service](#Service){Name: "stepfunctions", Port: "4585/tcp"})
Supported AWS/localstack services
var AvailableServices = map[Service]struct{}{ FixedPort: {}, CloudFormation: {}, CloudWatch: {}, CloudWatchLogs: {}, CloudWatchEvents: {}, DynamoDB: {}, DynamoDBStreams: {}, EC2: {}, ES: {}, Firehose: {}, IAM: {}, Kinesis: {}, Lambda: {}, Redshift: {}, Route53: {}, S3: {}, SecretsManager: {}, SES: {}, SNS: {}, SQS: {}, SSM: {}, STS: {}, StepFunctions: {}, }
AvailableServices provides a map of all services for faster searches
This section is empty.
type CloudformationResolverV2 struct {
}
func NewCloudformationResolverV2(i *Instance) *CloudformationResolverV2
NewCloudformationResolverV2 resolves the services ResolverV2 endpoint
type CloudwatchEventsResolverV2 struct {
}
func NewCloudwatchEventsResolverV2(i *Instance) *CloudwatchEventsResolverV2
NewCloudwatchEventsResolverV2 resolves the services ResolverV2 endpoint
type CloudwatchLogsResolverV2 struct {
}
func NewCloudwatchLogsResolverV2(i *Instance) *CloudwatchLogsResolverV2
NewCloudwatchLogsResolverV2 resolves the services ResolverV2 endpoint
type CloudwatchResolverV2 struct {
}
func NewCloudwatchResolverV2(i *Instance) *CloudwatchResolverV2
NewCloudwatchResolverV2 resolves the services ResolverV2 endpoint
type DynamoDbResolver struct {
}
func NewDynamoDbResolverV2(i *Instance) *DynamoDbResolver
NewDynamoDbResolverV2 resolves the services ResolverV2 endpoint
type DynamoDbStreamsResolverV2 struct {
}
func NewDynamoDbStreamsResolverV2(i *Instance) *DynamoDbStreamsResolverV2
NewDynamoDbStreamsResolverV2 resolves the services ResolverV2 endpoint
type Ec2ResolverV2 struct {
}
func NewEc2ResolverV2(i *Instance) *Ec2ResolverV2
NewEc2ResolverV2 resolves the services ResolverV2 endpoint
type ElasticSearchResolverV2 struct {
}
func NewElasticSearchResolverV2(i *Instance) *ElasticSearchResolverV2
NewElasticSearchResolverV2 resolves the services ResolverV2 endpoint
type FirehoseResolverV2 struct {
}
func NewFirehoseResolverV2(i *Instance) *FirehoseResolverV2
NewFirehoseResolverV2 resolves the services ResolverV2 endpoint
type IamResolverV2 struct {
}
func NewIamResolverV2(i *Instance) *IamResolverV2
NewIamResolverV2 resolves the services ResolverV2 endpoint
Instance manages the localstack
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel()
l, err := localstack.NewInstance() if err != nil { log.Fatalf("Could not connect to Docker %v", err) } if err := l.Start(); err != nil { log.Fatalf("Could not start localstack %v", err) } defer func() { // this should be t.Cleanup for better stability if err := l.Stop(); err != nil { log.Fatalf("Could not stop localstack %v", err) } }()
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-east-1"), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")), ) if err != nil { log.Fatalf("Could not get config %v", err) }
resolver := localstack.NewDynamoDbResolverV2(l) client := dynamodb.NewFromConfig(cfg, dynamodb.WithEndpointResolverV2(resolver))
myTestWithV2Client(client)
func NewInstance(opts ...InstanceOption) (*Instance, error)
NewInstance creates a new Instance Fails when Docker is not reachable
//nolint:all package main
import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/endpoints" "log"
"github.com/elgohr/go-localstack")
func main() { l, err := localstack.NewInstance() if err != nil { log.Fatalf("Could not connect to Docker %v", err) } if err := l.Start(); err != nil { log.Fatalf("Could not start localstack %v", err) } defer func() { // this should be t.Cleanup for better stability if err := l.Stop(); err != nil { log.Fatalf("Could not stop localstack %v", err) } }()
myTestWith(&aws.Config{
Credentials: credentials.NewStaticCredentials("not", "empty", ""),
DisableSSL: aws.Bool(true),
Region: aws.String(endpoints.UsWest1RegionID),
Endpoint: aws.String(l.Endpoint(localstack.SQS)),
})}
func myTestWith(_ *aws.Config) {}
NewInstanceCtx is NewInstance, but with Context
Endpoint returns the endpoint for the given service Endpoints are allocated dynamically (to avoid blocked ports), but are fix after starting the instance
func (i *Instance) EndpointV2(service Service) string
EndpointV2 returns the endpoint for the given service when used by aws-sdk-v2 Endpoints are allocated dynamically (to avoid blocked ports), but are fix after starting the instance
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel()
l, err := localstack.NewInstance() if err != nil { log.Fatalf("Could not connect to Docker %v", err) } if err := l.Start(); err != nil { log.Fatalf("Could not start localstack %v", err) } defer func() { // this should be t.Cleanup for better stability if err := l.Stop(); err != nil { log.Fatalf("Could not stop localstack %v", err) } }()
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-east-1"), config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(_, _ string, _ ...interface{}) (aws.Endpoint, error) { return aws.Endpoint{ PartitionID: "aws", URL: l.EndpointV2(localstack.SQS), SigningRegion: "us-east-1", HostnameImmutable: true, }, nil })), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")), ) if err != nil { log.Fatalf("Could not get config %v", err) }
myTestWithV2(cfg)
func (i *Instance) Start(services ...Service) error
Start starts the localstack
StartWithContext starts the localstack and ends it when the context is done.
Deprecated: Use Start/Stop instead, as shutdown is not reliable
Stop stops the localstack
type InstanceOption func(i *Instance)
InstanceOption is an option that controls the behaviour of localstack.
func WithClientFromEnv() (InstanceOption, error)
WithClientFromEnv configures the instance to use a client that respects environment variables.
WithClientFromEnvCtx like WithClientFromEnv but with context
WithLabels configures the labels that will be applied on the instance.
WithLogger configures the instance to use the specified logger.
WithTimeout configures the timeout for terminating the localstack instance. This was invented to prevent orphaned containers after panics. The default timeout is set to 5 minutes.
WithVersion configures the instance to use a specific version of localstack. Must be a valid version string or "latest".
type KinesisResolverV2 struct {
}
func NewKinesisResolverV2(i *Instance) *KinesisResolverV2
NewKinesisResolverV2 resolves the services ResolverV2 endpoint
type LambdaResolverV2 struct {
}
func NewLambdaResolverV2(i *Instance) *LambdaResolverV2
NewLambdaResolverV2 resolves the services ResolverV2 endpoint
type RedshiftResolverV2 struct {
}
func NewRedshiftResolverV2(i *Instance) *RedshiftResolverV2
NewRedshiftResolverV2 resolves the services ResolverV2 endpoint
type Route53ResolverV2 struct {
}
func NewRoute53ResolverV2(i *Instance) *Route53ResolverV2
NewRoute53ResolverV2 resolves the services ResolverV2 endpoint
type S3ResolverV2 struct {
}
func NewS3ResolverV2(i *Instance) *S3ResolverV2
NewS3ResolverV2 resolves the services ResolverV2 endpoint
type SecretsManagerResolverV2 struct {
}
func NewSecretsManagerResolverV2(i *Instance) *SecretsManagerResolverV2
NewSecretsManagerResolverV2 resolves the services ResolverV2 endpoint
Service represents an AWS service
type SesResolverV2 struct {
}
func NewSesResolverV2(i *Instance) *SesResolverV2
NewSesResolverV2 resolves the services ResolverV2 endpoint
type SnsResolverV2 struct {
}
func NewSnsResolverV2(i *Instance) *SnsResolverV2
NewSnsResolverV2 resolves the services ResolverV2 endpoint
type SqsResolverV2 struct {
}
func NewSqsResolverV2(i *Instance) *SqsResolverV2
NewSqsResolverV2 resolves the services ResolverV2 endpoint
type SsmResolverV2 struct {
}
func NewSsmResolverV2(i *Instance) *SsmResolverV2
NewSsmResolverV2 resolves the services ResolverV2 endpoint
type StepFunctionsResolverV2 struct {
}
func NewStepFunctionsResolverV2(i *Instance) *StepFunctionsResolverV2
NewStepFunctionsResolverV2 resolves the services ResolverV2 endpoint
type StsResolverV2 struct {
}
func NewStsResolverV2(i *Instance) *StsResolverV2
NewStsResolverV2 resolves the services ResolverV2 endpoint