Skip to content

feat(lambda-event-sources): add AT_TIMESTAMP event source mapping starting position#20741

Merged
mergify[bot] merged 5 commits intoaws:mainfrom
cecheta:at-timestamp
Jul 21, 2022
Merged

feat(lambda-event-sources): add AT_TIMESTAMP event source mapping starting position#20741
mergify[bot] merged 5 commits intoaws:mainfrom
cecheta:at-timestamp

Conversation

@cecheta
Copy link
Copy Markdown
Contributor

@cecheta cecheta commented Jun 14, 2022

Closes #17214

This PR adds AT_TIMESTAMP to the StartingPosition enum for lambda event source mappings.


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jun 14, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team June 14, 2022 21:32
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Jun 14, 2022
Copy link
Copy Markdown
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Hi @cecheta! Thanks for submitting this PR! I've provided some comments mostly surrounding the documentation around this feature. There's a lot of weird things going on, like the property only being allowed in Kinesis streams and being used in conjunction with AT_TIMESTAMP. So we need to be very careful with the docs.

*
* @default Required when startingPosition is AT_TIMESTAMP.
*/
readonly startingPositionTimestamp?: number
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
readonly startingPositionTimestamp?: number
readonly startingPositionTimestamp?: number;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/**
* The time from which to start reading, in Unix time seconds.
*
* @default Required when startingPosition is AT_TIMESTAMP.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not the correct use of default. The @default tag is meant to describe what happens if left blank -- should be @default - no timestamp. The information about when it's required is important, but put that in the regular documentation instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

/**
* The time from which to start reading, in Unix time seconds.
*
* @default Required when startingPosition is AT_TIMESTAMP.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same comment regarding this @default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i also see how @default is being used in startingPosition. I consider that wrong also. Would you please change that as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated both

LATEST = 'LATEST',

/**
* Start reading from a position defined by a time stamp.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This documentation should mention that if supplied, startingPositionTimestamp must be set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines +309 to +311
if (props.startingPosition === StartingPosition.AT_TIMESTAMP && !props.startingPositionTimestamp) {
throw new Error('startingPositionTimestamp must be provided when startingPosition is AT_TIMESTAMP');
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about when startingPositionTimestamp is set but props.startingPosition !== StartingPosition.AT_TIMESTAMP? I think we should throw an error also

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added another error and a test


/**
* Start reading from a position defined by a time stamp.
* Only supported for Amazon Kinesis streams.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happens when this is set for non Kinesis streams?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the docs to say that an error will occur

* Use an Amazon Kinesis stream as an event source for AWS Lambda.
*/
export class KinesisEventSource extends StreamEventSource {
private innerProps: KinesisEventSourceProps;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer you not do this and just pull out the props you're going to use. Looks like just a startingPositionTimestamp is necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

* __retryAttempts__: The maximum number of times a record should be retried in the event of failure.
* __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source.
* __startingPosition__: Will determine where to being consumption. 'LATEST' will start at the most recent record and ignore all records that arrived prior to attaching the event source, 'TRIM_HORIZON' will start at the oldest record and ensure you process all available data, while 'AT_TIMESTAMP' will start reading records from a specified time stamp.
* __startingPositionTimestamp__: The time stamp from which to start reading. Used in conjunction with __startingPosition__.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

README needs to mention that AT_TIMESTAMP only works for kinesis streams.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@kaizencc kaizencc changed the title feat(lambda): add AT_TIMESTAMP event source mapping starting position feat(lambda-event-sources): add AT_TIMESTAMP event source mapping starting position Jul 5, 2022
@mergify mergify bot dismissed kaizencc’s stale review July 9, 2022 21:20

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 21, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 925f311
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 76e0768 into aws:main Jul 21, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 21, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

comcalvi pushed a commit to comcalvi/aws-cdk that referenced this pull request Jul 25, 2022
…rting position (aws#20741)

Closes aws#17214

This PR adds `AT_TIMESTAMP` to the `StartingPosition` enum for lambda event source mappings.

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [X] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(@aws-cdk/aws-lambda): add support for AT_TIMESTAMP to lambda kinesis event source mapping

4 participants