-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(event-source): add SQS as Lambda event source #451
Conversation
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Let's stick with Queue to keep the language consistent.
tests/translator/input/streams.yaml
Outdated
@@ -25,3 +25,15 @@ Resources: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving SQS test to a separate file. This file is already getting overloaded.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we shouldn't be calling SQS as streams. SQS in itself should do. Thoughts ?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We do need to validate them separately now that these properties are not required
@@ -61,7 +61,7 @@ class LambdaEventSourceMapping(Resource): | |||
'Enabled': PropertyType(False, is_type(bool)), | |||
'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
tests/translator/input/streams.yaml
Outdated
@@ -25,3 +25,15 @@ Resources: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we should consider moving this to a separate file. And this file is explicitly named Streams and hence SQS doesn't belong here.
tests/translator/input/streams.yaml
Outdated
Type: SQS | ||
Properties: | ||
Queue: arn:aws:sqs:us-west-2:012345678901:my-queue | ||
BatchSize: 200 |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Batch size for SQS is between 1 and 10
"SQSFunctionMySqsQueue": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"BatchSize": 200, |
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.
BatchSize between 1 and 10
tests/translator/output/streams.json
Outdated
"SQSFunctionMySqsQueue": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"BatchSize": 200, |
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.
Batch size between 1 and 10
versions/2016-10-31.md
Outdated
```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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Queue: and not Stream:
…tchSize from 200 to 10 (max)
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.
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.
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.
This works, but I think you can do better :)
@@ -48,6 +49,10 @@ def to_cloudformation(self, **kwargs): | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
LGTM assuring json schema will do better validation in future
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.
Looks good to me !
* 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.