diff --git a/main.go b/main.go index 6d8f4058..243cd247 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,10 @@ func main() { switch cfg.Source { case "", config.SourceDynamo: - ddb := dynamodb.Load(*cfg, statsD, _kafka) + ddb, err := dynamodb.Load(*cfg, statsD, _kafka) + if err != nil { + logger.Fatal("Failed to load dynamodb", slog.Any("err", err)) + } if err = ddb.Validate(); err != nil { logger.Fatal("Failed to validate dynamodb", slog.Any("err", err)) } diff --git a/sources/dynamodb/dynamodb.go b/sources/dynamodb/dynamodb.go index f5b162a8..e318dd9d 100644 --- a/sources/dynamodb/dynamodb.go +++ b/sources/dynamodb/dynamodb.go @@ -42,14 +42,13 @@ type Store struct { const jitterSleepBaseMs = 50 const shardScannerInterval = 5 * time.Minute -func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) *Store { +func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) (*Store, error) { sess, err := session.NewSession(&aws.Config{ Region: ptr.ToString(cfg.DynamoDB.AwsRegion), Credentials: credentials.NewStaticCredentials(cfg.DynamoDB.AwsAccessKeyID, cfg.DynamoDB.AwsSecretAccessKey, ""), }) - if err != nil { - logger.Fatal("Failed to create session", slog.Any("err", err)) + return nil, fmt.Errorf("failed to create session, err: %w", err) } store := &Store{ @@ -73,7 +72,7 @@ func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) *Store store.shardChan = make(chan *dynamodbstreams.Shard) } - return store + return store, nil } func (s *Store) Validate() error {