events: add UnmarshalStreamImage and ToDynamoDBJSON helpers (#58)#624
Draft
MukundaKatta wants to merge 1 commit intoaws:mainfrom
Draft
events: add UnmarshalStreamImage and ToDynamoDBJSON helpers (#58)#624MukundaKatta wants to merge 1 commit intoaws:mainfrom
MukundaKatta wants to merge 1 commit intoaws:mainfrom
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Author
|
The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #58. Adds backwards-compatible converter helpers from
events.DynamoDBStreamRecordto the AWS SDK'sAttributeValueshape, without changing any existing public API.Approach: backwards-compatible
Did not change
DynamoDBStreamRecordfield 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).