-
Notifications
You must be signed in to change notification settings - Fork 15
Fix sqs message attribute #140
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
Open
kokobd
wants to merge
6
commits into
Nike-Inc:master
Choose a base branch
from
bellroy:fix-sqs-message-attribute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0b6b10
Support SQS message group id (#1)
kokobd f5c229c
MessageGroupId isn't included for non FIFO queues
kokobd 853a858
fix messageAttributes type of SQSEvent
kokobd 23b4bd6
add aws doc URL
kokobd b680faf
add CHANGELOG entry
kokobd 461afac
define sum type for kafka message attributes
kokobd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| {-# LANGUAGE QuasiQuotes #-} | ||
|
|
||
| module AWS.Lambda.Events.SQS.Spec where | ||
|
|
||
| import AWS.Lambda.Events.SQS | ||
| import Data.Aeson (eitherDecode) | ||
| import qualified Data.Map as M | ||
| import Data.ByteString.Lazy (ByteString) | ||
| import Test.Hspec (Spec, shouldBe, specify) | ||
| import Text.RawString.QQ (r) | ||
|
|
||
| spec :: Spec | ||
| spec = | ||
| specify "read sample payload" $ | ||
| eitherDecode samplePayload `shouldBe` Right expectedRecords | ||
|
|
||
| samplePayload :: ByteString | ||
| samplePayload = [r| | ||
| { | ||
| "Records": [ | ||
| { | ||
| "messageId": "11111111-2222-3333-4444-555555555555", | ||
| "receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...", | ||
| "body": "Hello from SQS!", | ||
| "attributes": { | ||
| "ApproximateReceiveCount": "1", | ||
| "SentTimestamp": "1523232000000", | ||
| "SenderId": "123456789012", | ||
| "ApproximateFirstReceiveTimestamp": "1523232000001", | ||
| "MessageGroupId": "group-1" | ||
| }, | ||
| "messageAttributes": { | ||
| "attribute1": { | ||
| "stringValue": "value1", | ||
| "stringListValues": [], | ||
| "binaryListValues": [], | ||
| "dataType": "String" | ||
| }, | ||
| "attribute2": { | ||
| "binaryValue": "dmFsdWUy", | ||
| "stringListValues": [], | ||
| "binaryListValues": [], | ||
| "dataType": "Binary" | ||
| } | ||
| }, | ||
| "md5OfBody": "9a0364b9e99bb480dd25e1f0284c8555", | ||
| "eventSource": "aws:sqs", | ||
| "eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:queue1", | ||
| "awsRegion": "us-east-1" | ||
| } | ||
| ] | ||
| } | ||
| |] | ||
|
|
||
| expectedRecords :: Records | ||
| expectedRecords = Records | ||
| { records = | ||
| [ SQSEvent | ||
| { messageId = "11111111-2222-3333-4444-555555555555" | ||
| , receiptHandle = "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a..." | ||
| , body = "Hello from SQS!" | ||
| , attributes = Attributes | ||
| { approximateReceiveCount = "1" | ||
| , sentTimestamp = "1523232000000" | ||
| , senderId = "123456789012" | ||
| , approximateFirstReceiveTimestamp = "1523232000001" | ||
| , messageGroupId = Just "group-1" | ||
| } | ||
| , messageAttributes = M.fromList | ||
| [ ( "attribute1" | ||
| , MessageAttributeValue | ||
| { stringValue = Just "value1" | ||
| , binaryValue = Nothing | ||
| , stringListValues = [] | ||
| , binaryListValues = [] | ||
| , dataType = "String" | ||
| } | ||
| ) | ||
| , ( "attribute2" | ||
| , MessageAttributeValue | ||
| { stringValue = Nothing | ||
| , binaryValue = Just "value2" | ||
| , stringListValues = [] | ||
| , binaryListValues = [] | ||
| , dataType = "Binary" | ||
| } | ||
| ) | ||
| ] | ||
| , md5OfBody = "9a0364b9e99bb480dd25e1f0284c8555" | ||
| , eventSource = "aws:sqs" | ||
| , eventSourceARN = "arn:aws:sqs:us-east-1:123456789012:queue1" | ||
| , awsRegion = "us-east-1" | ||
| } | ||
| ] | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually a sum type and should it be modeled as such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, but
dataTypeis slightly more complex than a closed enum. It can beString,Number,Binary, or one of the three plus.custom-label, for exampleString.hello-world. We could have something like:Do you have any suggestion about how to name these things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a discussion @kokobd and I had over voice: we decided on the call it's probably best to keep this mapping as close to what SQS invokes, so library users can see how to use it. But now, looking at the snippet you've posted above, I think something like that would be quite workable, perhaps with
customTypeLabel :: Maybe Text:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should make types ADT/Haskell-like where they fit. It's unfortunate that this is so often made so difficult :)
From here:
So... kind of odd. More precision than an f64, less exponent range than an f128.
Since we can't match the domain exactly, we'll need to make it larger. I think my lean would be to use a Number128 or a Scientific. Both are strictly larger, but not quite so large as Text. Other than that, this last recommendation looks good to me, and I'm not too attached to any specific number type approach.