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(lambda): event-source maxBatchingWindow property #4260

Merged
merged 19 commits into from
Sep 30, 2019

Conversation

nmussy
Copy link
Contributor

@nmussy nmussy commented Sep 26, 2019

Implements the new maxBatchingWindow property

  • added to Kinesis and Dynamo event sources
  • throw if the property is outside the 300s max bound
  • remove redundant code in KinesisEventSource and DynamoEventSource into common StreamEventSource

Fixes #4257


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@mergify
Copy link
Contributor

mergify bot commented Sep 26, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

* The maximum amount of time to gather records before invoking the function.
* Maximum of Duration.minutes(5)
*
* @default Duration.seconds(0)
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 couldn't find documentation on the default, but I'm assuming that since this is a new feature, the previous behavior is the default.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

*
* @default Duration.seconds(0)
*/
readonly maximumBatchingWindow?: Duration;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use terser form max instead of maximum everywhere.

packages/@aws-cdk/aws-lambda-event-sources/lib/dynamodb.ts Outdated Show resolved Hide resolved
@nmussy nmussy changed the title feat(lambda): event-source maximumBatchingWindow property feat(lambda): event-source maxBatchingWindow property Sep 27, 2019
@mergify mergify bot dismissed nija-at’s stale review September 27, 2019 11:56

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@@ -4,3 +4,4 @@ export * from './sqs';
export * from './s3';
export * from './sns';
export * from './api';
export * from './stream';
Copy link
Contributor

@nija-at nija-at Sep 27, 2019

Choose a reason for hiding this comment

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

This is an internal refactoring to reduce code duplication. I don't see value in exporting these to consumers (i.e., public API). In fact, it might limit our flexibility to change this in the future.

import lambda = require('@aws-cdk/aws-lambda');
import {Duration} from "@aws-cdk/core";

export interface StreamingEventSourceProps {
Copy link
Contributor

@nija-at nija-at Sep 27, 2019

Choose a reason for hiding this comment

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

Keep the name consistent - use StreamEventSourceProps.

export abstract class StreamEventSource implements lambda.IEventSource {
protected constructor(protected readonly props: StreamingEventSourceProps, protected readonly maxBatchSize: number) {
if (this.props.batchSize !== undefined && (this.props.batchSize < 1 || this.props.batchSize > maxBatchSize)) {
throw new Error(`Maximum batch size must be between 1 and ${maxBatchSize} inclusive (given ${this.props.batchSize})`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels somewhat over-delegated. Instead of passing maxBatchSize down here, throw this error in each of the subclasses.

throw new Error('Cannot bind StreamEventSource, use DynamoEventSource or KinesisEventSource');
}

protected getEventSourceMappingOptions(eventSourceArn: string): lambda.EventSourceMappingOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here about over-delegation. Don't pass the eventSourceArn here. Instead insert it into the struct, returned by this method, at the calling point in the subclasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would break the requirement of the EventSourceMappingOptions return type, which I'd like to keep. I could change it to Omit<EventSourceMappingOptions, 'eventSourceArn'>, I'll see if JSII is alright with it.

Copy link
Contributor

@nija-at nija-at Sep 27, 2019

Choose a reason for hiding this comment

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

I see, good point.

How about renaming the method signature to enrichMappingOptions(options: lambda.EventSourceMappingOptions) which would add the stream-related properties and return it back?

@@ -0,0 +1,52 @@
import lambda = require('@aws-cdk/aws-lambda');
import {Duration} from "@aws-cdk/core";
Copy link
Contributor

Choose a reason for hiding this comment

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

Switch to single quotes.

@@ -1,44 +1,26 @@
import dynamodb = require('@aws-cdk/aws-dynamodb');
import lambda = require('@aws-cdk/aws-lambda');
import {StreamEventSource, StreamingEventSourceProps} from "./stream";
Copy link
Contributor

Choose a reason for hiding this comment

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

Switch to use single quotes

@mergify mergify bot dismissed nija-at’s stale review September 27, 2019 17:16

Pull request has been modified.

@nmussy
Copy link
Contributor Author

nmussy commented Sep 27, 2019

The PR should be good to go. I was going to create a test suite for stream.ts, but it's an abstract class with a protected constructor.
It's all well covered anyway, except for the unreachable error:

throw new Error('Cannot bind StreamEventSource, use DynamoEventSource or KinesisEventSource');

EDIT: Never mind, I just remembered that TypeScript had abstract methods too. All good!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 30, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

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.

Provide lambda kinesis with new property MaximumBatchingWindowInSeconds
3 participants