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

feat(event-source): add SQS as Lambda event source #451

Merged
merged 11 commits into from
Jun 1, 2018
Merged

feat(event-source): add SQS as Lambda event source #451

merged 11 commits into from
Jun 1, 2018

Conversation

brettstack
Copy link
Contributor

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.

@brettstack brettstack requested review from sanathkr and jfuss May 30, 2018 17:10
@brettstack brettstack self-assigned this May 30, 2018
sanathkr
sanathkr previously approved these changes May 31, 2018
Copy link
Contributor

@sanathkr sanathkr left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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?).

Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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.

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.

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 ?

Copy link
Contributor Author

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())

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.

Copy link
Contributor

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())

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

@@ -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:

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.

Type: SQS
Properties:
Queue: arn:aws:sqs:us-west-2:012345678901:my-queue
BatchSize: 200

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,

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,

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

"SQSFunctionMySqsQueue": {
"Type": "AWS::Lambda::EventSourceMapping",
"Properties": {
"BatchSize": 200,

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

```yaml
Type: SQS
Properties:
Stream: arn:aws:sqs:us-west-2:012345678901:my-queue # NOTE: FIFO SQS Queues are not yet supported

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:

digioak-zz
digioak-zz previously approved these changes Jun 1, 2018
Copy link
Contributor

@sanathkr sanathkr left a 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.

Copy link
Contributor

@sanathkr sanathkr left a 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:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

sanathkr
sanathkr previously approved these changes Jun 1, 2018
Copy link
Contributor

@sanathkr sanathkr left a 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

Copy link

@muthiah90 muthiah90 left a 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 !

@brettstack brettstack merged commit a5a3845 into aws:develop Jun 1, 2018
brettstack added a commit that referenced this pull request Jun 11, 2018
* 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)
brettstack added a commit that referenced this pull request Jun 12, 2018
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants