Just a simple way to set up the config connect to localstack
This is my docker-compose for the localstack all services running below port 4566
Function to create an AWS config connect to Localstack (DynamoDB)
func CreateLocalClient() *dynamodb.Client {
awsEndpoint := "http://localhost:4566"
awsRegion := "us-west-2"
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(awsRegion),
config.WithClientLogMode(aws.LogRequest|aws.LogRetries),
)
if err != nil {
panic(err)
}
cfg.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: awsEndpoint,
SigningRegion: awsRegion,
}, nil
})
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}
return dynamodb.NewFromConfig(cfg)
}
Github refer : https://github.com/kobee-tech-stack/aws-lambda-golang-serverless-framework/blob/local/services/dynamodb.go