Skip to content

Commit

Permalink
Move Fatal call out of DynamoDB Load (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Jan 27, 2024
1 parent 2d490bc commit 2d5bb4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
7 changes: 3 additions & 4 deletions sources/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down

0 comments on commit 2d5bb4b

Please sign in to comment.