Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create dynamo.StreamRecord to avoid json.Unmarshall issue #38

Merged
merged 1 commit into from
Jan 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions dynamo/dynamo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"

"github.com/apex/go-apex"
"github.com/aws/aws-sdk-go/service/dynamodbstreams"
"github.com/aws/aws-sdk-go/service/dynamodb"
)

// Event represents a Dynamo event with one or more records.
Expand All @@ -15,12 +15,23 @@ type Event struct {

// Record represents a single Dynamo record.
type Record struct {
EventID string `json:"eventID"`
EventName string `json:"eventName"`
EventSource string `json:"eventSource"`
EventVersion string `json:"eventVersion"`
AWSRegion string `json:"awsRegion"`
Dynamodb *dynamodbstreams.StreamRecord `json:"dynamodb"`
EventID string `json:"eventID"`
EventName string `json:"eventName"`
EventSource string `json:"eventSource"`
EventVersion string `json:"eventVersion"`
AWSRegion string `json:"awsRegion"`
Dynamodb *StreamRecord `json:"dynamodb"`
}

// StreamRecord represents a Dynamo stream records
type StreamRecord struct {
ApproximateCreationDateTime int64
Keys map[string]*dynamodb.AttributeValue
NewImage map[string]*dynamodb.AttributeValue
OldImage map[string]*dynamodb.AttributeValue
SequenceNumber string
SizeBytes int64
StreamViewType string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these ones don't need tags as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, tags are not required since the JSON keys have the same casing.

Example:

{
  "eventID": "a4667189b69049238be6e19dca1b0b68",
  "eventName": "INSERT",
  "eventVersion": "1.1",
  "eventSource": "aws:dynamodb",
  "awsRegion": "us-east-1",
  "dynamodb": {
    "ApproximateCreationDateTime": 1483834200,
    "Keys": {
      "id": {
        "S": "123"
      }
    },
    "NewImage": {
      "id": {
        "S": "123"
      },
      "name": {
        "S": "bob"
      }
    },
    "SequenceNumber": "123456700000000012345678901",
    "SizeBytes": 100,
    "StreamViewType": "NEW_IMAGE"
  },
  "eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789012:table\/table_name\/stream\/2017-01-01T00:00:00.000"
}

docs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird ok cool

}

// Handler handles Dynamo events.
Expand Down