Skip to content

events: add UnmarshalStreamImage and ToDynamoDBJSON helpers (#58)#624

Draft
MukundaKatta wants to merge 1 commit intoaws:mainfrom
MukundaKatta:feat/dynamodb-stream-sdk-converter
Draft

events: add UnmarshalStreamImage and ToDynamoDBJSON helpers (#58)#624
MukundaKatta wants to merge 1 commit intoaws:mainfrom
MukundaKatta:feat/dynamodb-stream-sdk-converter

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

Refs #58. Adds backwards-compatible converter helpers from events.DynamoDBStreamRecord to the AWS SDK's AttributeValue shape, without changing any existing public API.

Approach: backwards-compatible

Did not change DynamoDBStreamRecord field types. The recurring concern in the issue thread was the SDK v1 vs v2 split and the binary-size cost of pulling in the SDK. This PR introduces no new module deps — helpers convert via canonical DynamoDB JSON.

What's added

  • events/dynamodb_helpers.go:
    • UnmarshalStreamImage(image map[string]DynamoDBAttributeValue, out interface{}) error — direct unmarshal-into-struct that mirrors the StackOverflow workaround referenced in the issue.
    • (DynamoDBAttributeValue).ToDynamoDBJSON() ([]byte, error) — render to canonical DynamoDB JSON.
    • ToDynamoDBJSONMap(map[string]DynamoDBAttributeValue) ([]byte, error).
    • (DynamoDBStreamRecord).ToDynamoDBJSON() ([]byte, error) — full envelope.
  • events/dynamodb_helpers_test.go — 8 tests covering scalars, nested map/list, null, set types, testdata round-trip, and envelope omitempty behavior.

Test plan

  • go build ./... clean.
  • go vet ./events/... clean.
  • go test ./events/... passes (existing + 8 new).
  • No existing public API touched.

Provide a backwards-compatible bridge between events.DynamoDBStreamRecord
and the AWS SDK's dynamodb.AttributeValue without forcing a hard SDK
dependency on aws-lambda-go.

- UnmarshalStreamImage: decode a Keys/NewImage/OldImage map directly
  into a user struct using standard json tags.
- DynamoDBAttributeValue.ToDynamoDBJSON / ToDynamoDBJSONMap: emit the
  canonical DynamoDB JSON wire form for hand-off to either aws-sdk-go
  or aws-sdk-go-v2.
- DynamoDBStreamRecord.ToDynamoDBJSON: convenience envelope for all
  three image fields.

Tests cover scalar, nested, null, set and testdata cases. Existing
public API is unchanged.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.06%. Comparing base (815d21f) to head (40688d8).

Files with missing lines Patch % Lines
events/dynamodb_helpers.go 73.91% 13 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #624      +/-   ##
==========================================
- Coverage   75.12%   75.06%   -0.06%     
==========================================
  Files          36       37       +1     
  Lines        1419     1488      +69     
==========================================
+ Hits         1066     1117      +51     
- Misses        274      287      +13     
- Partials       79       84       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MukundaKatta
Copy link
Copy Markdown
Author

The TestEnableSigterm failure on 1.15 / 1.21 looks unrelated. It's in the lambda/ package, this PR only adds new files in events/. The failure is the Docker-backed Lambda runtime timing out on init (Reset initiated: Timeout) which I've seen as flaky on the runners. Happy to rebase if a maintainer wants a re-run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants