Repository navigation
feat(event-source): add SQS as Lambda event source - #451
Conversation
sanathkr
left a comment
There was a problem hiding this comment.
LGTM in general. I have a few comments you can choose to ignore ;)
| MyTrigger: | ||
| Type: SQS | ||
| Properties: | ||
| Queue: arn:aws:sqs:us-east-1:123456789012:my-queue |
There was a problem hiding this comment.
should we call this property QueueArn instead? I wonder if users might get confused and specify a queue name here
There was a problem hiding this comment.
I went with Queue to be consistent with Stream. Though I agree, QueueArn is more descriptive. If we want in the future we can add QueueArn (and StreamArn) leave Queue as an alias (and possibly deprecate?).
There was a problem hiding this comment.
Fair enough. Let's stick with Queue to keep the language consistent.
| Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291 | ||
| BatchSize: 200 | ||
| StartingPosition: LATEST | ||
| SQSFunction: |
There was a problem hiding this comment.
Consider moving SQS test to a separate file. This file is already getting overloaded.
There was a problem hiding this comment.
Yes we should consider moving this to a separate file. And this file is explicitly named Streams and hence SQS doesn't belong here.
| The pull events are the streams--Kinesis and DynamoDB Streams. Both of these correspond to an EventSourceMapping in | ||
| Lambda, and require that the execution role be given to Kinesis or DynamoDB Streams, respectively. | ||
| The pull events are Kinesis Streams, DynamoDB Streams, and SQS Queues. All of these correspond to an EventSourceMapping in | ||
| Lambda, and require that the execution role be given to Kinesis Streams, DynamoDB Streams, or SQS Streams, respectively. |
There was a problem hiding this comment.
I suppose we shouldn't be calling SQS as streams. SQS in itself should do. Thoughts ?
There was a problem hiding this comment.
Good catch; that was a miss. I refer to it as SQS Queues in the first sentence.
| 'Stream': PropertyType(False, is_str()), | ||
| 'Queue': PropertyType(False, is_str()), | ||
| 'BatchSize': PropertyType(False, is_type(int)), | ||
| 'StartingPosition': PropertyType(False, is_str()) |
There was a problem hiding this comment.
I suppose all properties are changed to not required (False) so as to support event source mapping for both Streams (DynamoDB and Kinesis) and SQS. But aren't we actually missing on validation ? I can create an Event Source mapping for DDB streams without the StartingPosition specified, it will pass this check but will end up in an error from CFN.
There was a problem hiding this comment.
Good point. We do need to validate them separately now that these properties are not required
| 'EventSourceArn': PropertyType(True, is_str()), | ||
| 'FunctionName': PropertyType(True, is_str()), | ||
| 'StartingPosition': PropertyType(True, is_str()) | ||
| 'StartingPosition': PropertyType(False, is_str()) |
There was a problem hiding this comment.
Same as the previous comment. Aren't we letting go the validation of StartingPosition for streams because of SQS which doesn't require it.
There was a problem hiding this comment.
JSON Schema validation will pick this up once we turn it on (it's currently not doing anything with failed JSON Schemas as we're not yet ready). Would prefer to not add additional validation right now.
There was a problem hiding this comment.
What if someone forgot to set the Queue property? SAM Translator will crash instead of giving them a validation error. After turning on JSON Schema, we do need a deeper scrub of code. This extra validation won't increase the surface area of the scrub significantly IMO
| Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291 | ||
| BatchSize: 200 | ||
| StartingPosition: LATEST | ||
| SQSFunction: |
There was a problem hiding this comment.
Yes we should consider moving this to a separate file. And this file is explicitly named Streams and hence SQS doesn't belong here.
| Type: SQS | ||
| Properties: | ||
| Queue: arn:aws:sqs:us-west-2:012345678901:my-queue | ||
| BatchSize: 200 |
There was a problem hiding this comment.
Batch size for SQS is only between 1 and 10
| "SQSFunctionMySqsQueue": { | ||
| "Type": "AWS::Lambda::EventSourceMapping", | ||
| "Properties": { | ||
| "BatchSize": 200, |
There was a problem hiding this comment.
Batch size for SQS is between 1 and 10
| "SQSFunctionMySqsQueue": { | ||
| "Type": "AWS::Lambda::EventSourceMapping", | ||
| "Properties": { | ||
| "BatchSize": 200, |
| "SQSFunctionMySqsQueue": { | ||
| "Type": "AWS::Lambda::EventSourceMapping", | ||
| "Properties": { | ||
| "BatchSize": 200, |
| ```yaml | ||
| Type: SQS | ||
| Properties: | ||
| Stream: arn:aws:sqs:us-west-2:012345678901:my-queue # NOTE: FIFO SQS Queues are not yet supported |
There was a problem hiding this comment.
This should be Queue: and not Stream:
…tchSize from 200 to 10 (max)
sanathkr
left a comment
There was a problem hiding this comment.
Can we add validation for the Queue and Stream property? In the current code, if Queue or Stream property is not specified, customers will get an invalid CFN whichi will fail deployment with a weird error.
sanathkr
left a comment
There was a problem hiding this comment.
This works, but I think you can do better :)
| except NotImplementedError: | ||
| function_name_or_arn = function.get_runtime_attr("arn") | ||
|
|
||
| if not self.Stream and not self.Queue: |
There was a problem hiding this comment.
Can you instead add a validate functino to each subclass that gets called here? Each subclass can then validate and return a customized error message. What do you think?
There was a problem hiding this comment.
I deliberately went with this simpler approach since this is temporary code and I think the error message is clear enough even when they are combined for both cases.
sanathkr
left a comment
There was a problem hiding this comment.
LGTM assuring json schema will do better validation in future
* doc: update DESIGN.md to include an Overview and entry point for SAM (#370) * Update DESIGN.md to include an Overview and entry point for SAM * Updated wording in DESIGN.md based on PR feedback * docs(example): improve microservice-http-endpoint-python3 example (#415) * Remove unnecessary index.js" * Moved common config to template Globals and uncomment debug log. * Add sample payload and commands for testing. * Rename test script as a script. * Exit from script after command. * Simplify use case for easier startup. - Move table creation into template. - Eliminates need to provide table name in every REST call. - Fix GET with no params. - Split test.sh script from output log. * Address requested changes. * doc(example): update api_backend example to use ES6 arrow function immediate return (#446) Since this code is using ES6 we can use the short version of returning a param * feat(event-source): add SQS as Lambda event source (#451) * feat(cli): add lightweight transformer cli (#459) * bug: fix ANY method ARN generation using wildcard (#449) * fix(event-source): fix SQS Queue schema to allow intrinsic functions (#465) * fix: log a warning on invalid schema validation (#466)
* doc: update DESIGN.md to include an Overview and entry point for SAM (#370) * Update DESIGN.md to include an Overview and entry point for SAM * Updated wording in DESIGN.md based on PR feedback * docs(example): improve microservice-http-endpoint-python3 example (#415) * Remove unnecessary index.js" * Moved common config to template Globals and uncomment debug log. * Add sample payload and commands for testing. * Rename test script as a script. * Exit from script after command. * Simplify use case for easier startup. - Move table creation into template. - Eliminates need to provide table name in every REST call. - Fix GET with no params. - Split test.sh script from output log. * Address requested changes. * doc(example): update api_backend example to use ES6 arrow function immediate return (#446) Since this code is using ES6 we can use the short version of returning a param * feat(event-source): add SQS as Lambda event source (#451) * feat(cli): add lightweight transformer cli (#459) * bug: fix ANY method ARN generation using wildcard (#449) * fix(event-source): fix SQS Queue schema to allow intrinsic functions (#465) * fix: log a warning on invalid schema validation (#466)
Issue #, if available:
Description of changes:
Adds support for SQS as an event source. This feature is not yet supported by AWS (pre-announced earlier this year) and will not be merged to master until it is available.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.