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 AwsCompileStreamEvents plugin #2250

Merged
merged 11 commits into from Oct 7, 2016

Conversation

pmuens
Copy link
Contributor

@pmuens pmuens commented Oct 1, 2016

What did you implement:

_Implementing Issue:_ #1441 and #1608

Adds support for the stream event definition (which covers DynamoDB and Kinesis streams). No need to set it up through custom resources anymore.

How did you implement it:

Introduced a new plugin which will compile the corresponding EventSourceMappings for CloudFormation. Furthermore the IamRoleStatements are updated so that the Lambda function can be called when something in the stream is happening.

How can we verify it:

First of all you need to create a new DynamoDB table and set up a new Stream for that table (In Overview --> Stream details --> Manage Stream / Kinesis stream . Copy and paste the ARN for the corresponding stream.

Next up use this serverless.yml file and paste the ARN you've just copied:

service: new-test-service

provider:
  name: aws
  runtime: nodejs4.3

functions:
  hello:
    handler: handler.hello
    events:
      - stream: arn:aws:dynamodb:us-east-1:XXXXXX:table/foo/stream/2016-10-01T21:14:36.344
      - stream:
          arn: arn:aws:dynamodb:us-east-1:XXXXXX:table/bar/stream/2016-10-01T21:14:31.803
          batchSize: 20
          startingPosition: TRIM_HORIZON
          enabled: true
      - stream: arn:aws:kinesis:us-east-1:XXXXXX:stream/baz
      - stream:
          arn: arn:aws:kinesis:us-east-1:XXXXXX:stream/qux
          batchSize: 50
          startingPosition: LATEST
          enabled: false

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config/commands/resources
  • Change ready for review message below

_Is this ready for review?:_ YES

@pmuens pmuens added this to the v1.0-ideas milestone Oct 1, 2016
@pmuens pmuens self-assigned this Oct 1, 2016
@pmuens pmuens mentioned this pull request Oct 1, 2016
6 tasks
@pmuens pmuens changed the title Add aws compile stream events plugin Add AwsCompileStreamEvents plugin Oct 1, 2016
@pmuens pmuens assigned eahefnawy and unassigned pmuens Oct 3, 2016
@pmuens
Copy link
Contributor Author

pmuens commented Oct 3, 2016

@eahefnawy would be great if you could review it

@mthenw @ac360 your feedback would be also very valuable!

@pmuens pmuens force-pushed the add-aws-compile-stream-events-plugin branch 2 times, most recently from 7ee580c to 9228a35 Compare October 3, 2016 22:46
@mthenw
Copy link
Contributor

mthenw commented Oct 4, 2016

I'm personally not sure if it's not confusing that there is one event type (stream) for both DynamoDB and Kinesis streams. Looks like they share the same params so maybe it's OK.

Would be great if docs would also show how to create Kinesis stream via custom resources and pass ARN to event source config.

Copy link
Member

@eahefnawy eahefnawy left a comment

Choose a reason for hiding this comment

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

@pmuens we shouldn't put the table name in the logical ID of the event mapping resource. I tried using a table named test-stream and it failed because it's not alpha numeric.

Other than that, it's working great. 👍 for handling the permissions as well, it's interesting that this is the first event that actually requires the lambda function to have permission via roles, not the other way around by adding a lambda:permission resource.

@pmuens pmuens force-pushed the add-aws-compile-stream-events-plugin branch from 9228a35 to c7ac744 Compare October 4, 2016 20:53
@pmuens
Copy link
Contributor Author

pmuens commented Oct 4, 2016

@eahefnawy @mthenw thanks for the feedback.

I just refactored the resource logical Id name generation so that all non-alphanumerics are removed (so e.g. users-table will be userstable) and added a test for that as well.

We need those names inside of the resource logical id so that they are unique (and also easier to overwrite via custom resources). I've tried to do it with a counter variable (like it's done in other plugins) but this will break when you re-arrange or update the streams.

@eahefnawy
Copy link
Member

@pmuens yeah you're right ... I was about to suggest removing the dynamodb label as well since they're all streams after all, but I realized that it might conflict with a kinesis stream of the same name. Thanks for clarification.

G2M from my side 👍

@pmuens
Copy link
Contributor Author

pmuens commented Oct 5, 2016

Awesome! Thanks for the review @eahefnawy

@flomotlik could you take a look at it and merge it if it's appropriate? Thanks!

@pmuens pmuens force-pushed the add-aws-compile-stream-events-plugin branch from ccad494 to 9d63ba0 Compare October 5, 2016 19:54
events:
- stream:
arn: some:kinesis:stream:arn
bathSize: 100

Choose a reason for hiding this comment

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

Is this a typo? bathSize -> batchSize ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn! Good catch @screamish

Just pushed an update which will fix this!

Copy link
Member

Choose a reason for hiding this comment

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

"bathSize" 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😹 #documentationGems

Copy link
Contributor

@flomotlik flomotlik left a comment

Choose a reason for hiding this comment

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

Good stuff. A few changes in the docs to make sure that users are aware that we're not actually creating the Kinesis or DynamoDB ourselves

@@ -0,0 +1,56 @@
# Compile Stream Events
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this README. Its basically just a copy of the documentation so the whole file can be removed.


# DynamoDB / Kinesis Streams

This setup specifies that the `compute` function should be triggered whenever the corresponding DynamoDB table is modified (e.g. a new entry is added).
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention that we do not create the DynamoDB, but it only connects to a previously created one.

compute:
handler: handler.compute
events:
- stream: some:dynamodb:stream:arn
Copy link
Contributor

Choose a reason for hiding this comment

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

Add 2 different stream configs, one with an ARN and one that uses the Ref syntax and mention that you can reference a dynamodb or kinesis stream created in the same service through Ref


## Setting the BatchSize and StartingPosition

This configuration sets up a disabled Kinesis stream event for the `preprocess` function which has a batch size of `100`. The starting position is
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, mention that you're not creating the Kinesis Stream

@pmuens pmuens force-pushed the add-aws-compile-stream-events-plugin branch from dc33892 to b6f60b6 Compare October 7, 2016 15:59
@pmuens
Copy link
Contributor Author

pmuens commented Oct 7, 2016

@flomotlik just update the PR with the proposed changes.

Unfortunately we cannot use Ref as it will only return the name of the stream for a Kinesis stream so I've used Fn::GetAtt to get the ARN.

Furthermore I've added a commented out example to all the serverless.yml files.

@flomotlik flomotlik merged commit 5e61aa5 into master Oct 7, 2016
@flomotlik flomotlik deleted the add-aws-compile-stream-events-plugin branch October 7, 2016 17:34
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

5 participants