-
-
Notifications
You must be signed in to change notification settings - Fork 135
4.2. Changing Event Store
Rafał Lorenz edited this page Jun 29, 2019
·
1 revision
To use AWS DynamoDB event store we need to add localstack container. This way we can use a fully functional local AWS cloud stack.
dependencies:
+# AWS localstack (for local development)
+ - name: microservice
+ version: 0.1.0
+ repository: "file://../microservice"
+ alias: localstack
+ condition: localstack.enabled
ingress:
paths:
+ - path: /localstack
+ backend:
+ serviceName: go-api-boilerplate-localstack
+ servicePort: 4567
+ # AWS localstack https://github.com/localstack/localstack
+ localstack:
+ enabled: true
+ nameOverride: localstack
+ image:
+ repository: localstack/localstack
+ tag: 0.8.10
+ pullPolicy: IfNotPresent
+ service:
+ ports:
+ - name: dynamodb
+ internalPort: 4569
+ externalPort: 4569
+ - name: ui
+ internalPort: 4567
+ externalPort: 4567
+ env:
+ - name: SERVICES
+ valueFrom: "dynamodb:4569"
+ - name: PORT_WEB_UI
+ valueFrom: 4567
user:
env:
+ - name: AWS_REGION
+ valueFrom:
+ configMapKeyRef:
+ key: AWS_REGION
+ name: go-api-boilerplate-app
+ - name: AWS_ENDPOINT
+ valueFrom:
+ configMapKeyRef:
+ key: AWS_ENDPOINT
+ name: go-api-boilerplate-app
configMap:
data:
+ AWS_REGION: 'us-east-1'
+ AWS_ENDPOINT: 'http://go-api-boilerplate-localstack:4569'
Finally we can switch memory event store to DynamoDB one as follow:
package main
import (
+ "github.com/aws/aws-sdk-go/aws"
- "github.com/vardius/go-api-boilerplate/pkg/eventstore/memory"
+ "github.com/vardius/go-api-boilerplate/pkg/eventstore/dynamodb"
)
type config struct {
+ AwsRegion string `env:"AWS_REGION" envDefault:"us-east-1"`
+ AwsEndpoint string `env:"AWS_ENDPOINT" envDefault:"http://localhost:4569"`
}
func main() {
ctx := context.Background()
cfg := config{}
env.Parse(&cfg)
+ awsConfig := &aws.Config{
+ Region: aws.String(cfg.AwsRegion),
+ Endpoint: aws.String(cfg.AwsEndpoint),
+ }
- eventStore := eventstore.New()
+ eventStore := eventstore.New("events", awsConfig)