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

Add Kinesis Stream Metadata to firehose event #188

Merged
merged 3 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
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
23 changes: 16 additions & 7 deletions events/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ package events

// KinesisFirehoseEvent represents the input event from Amazon Kinesis Firehose. It is used as the input parameter.
type KinesisFirehoseEvent struct {
InvocationID string `json:"invocationId"`
DeliveryStreamArn string `json:"deliveryStreamArn"`
Region string `json:"region"`
Records []KinesisFirehoseEventRecord `json:"records"`
InvocationID string `json:"invocationId"`
DeliveryStreamArn string `json:"deliveryStreamArn"`
SourceKinesisStreamArn string `json:"sourceKinesisStreamArn"`
Region string `json:"region"`
Records []KinesisFirehoseEventRecord `json:"records"`
}

type KinesisFirehoseEventRecord struct {
RecordID string `json:"recordId"`
ApproximateArrivalTimestamp MilliSecondsEpochTime `json:"approximateArrivalTimestamp"`
Data []byte `json:"data"`
RecordID string `json:"recordId"`
ApproximateArrivalTimestamp MilliSecondsEpochTime `json:"approximateArrivalTimestamp"`
Data []byte `json:"data"`
KinesisFirehoseRecordMetadata KinesisFirehoseRecordMetadata `json:"kinesisRecordMetadata"`
}

// Constants used for describing the transformation result
Expand All @@ -32,3 +34,10 @@ type KinesisFirehoseResponseRecord struct {
Result string `json:"result"` // The status of the transformation. May be TransformedStateOk, TransformedStateDropped or TransformedStateProcessingFailed
Data []byte `json:"data"`
}

type KinesisFirehoseRecordMetadata struct {
ShardID string `json:"shardId"`
PartitionKey string `json:"partitionKey"`
SequenceNumber string `json:"sequenceNumber"`
ApproximateArrivalTimestamp MilliSecondsEpochTime `json:"approximateArrivalTimestamp"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CI failed (https://travis-ci.org/aws/aws-lambda-go/builds/530382884). Need to check if the type needs to be string, or if the test data is wrong.

...
--- FAIL: TestSampleTransformation (0.00s)
    firehose_test.go:50: could not unmarshal event. details: json: cannot unmarshal string into Go struct field KinesisFirehoseRecordMetadata.approximateArrivalTimestamp of type int64
...

Copy link
Collaborator

Choose a reason for hiding this comment

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

found a reference internally and a sample event in the console - I will update the test data and merge

}
7 changes: 4 additions & 3 deletions events/testdata/kinesis-firehose-event.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"invocationId": "invoked123",
"deliveryStreamArn": "aws:lambda:events",
"sourceKinesisStreamArn": "arn:aws:kinesis:us-east-1:123456789012:stream/test",
"region": "us-west-2",
"records": [
{
Expand All @@ -10,7 +11,7 @@
"kinesisRecordMetadata": {
"shardId": "shardId-000000000000",
"partitionKey": "4d1ad2b9-24f8-4b9d-a088-76e9947c317a",
"approximateArrivalTimestamp": "1507217624302",
"approximateArrivalTimestamp": 1507217624302,
"sequenceNumber": "49546986683135544286507457936321625675700192471156785154",
"subsequenceNumber": ""
}
Expand All @@ -22,10 +23,10 @@
"kinesisRecordMetadata": {
"shardId": "shardId-000000000001",
"partitionKey": "4d1ad2b9-24f8-4b9d-a088-76e9947c318a",
"approximateArrivalTimestamp": "1507217624302",
"approximateArrivalTimestamp": 1507217624302,
"sequenceNumber": "49546986683135544286507457936321625675700192471156785155",
"subsequenceNumber": ""
}
}
]
}
}