-
Notifications
You must be signed in to change notification settings - Fork 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(lambda-event-sources): expose eventSourceMappingId
#5689
feat(lambda-event-sources): expose eventSourceMappingId
#5689
Conversation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…tSourceMapping Exposes the Ref of `AWS::Lambda::EventSourceMapping` as eventSourceMappingId property on the EventSourceMapping and further on the SqsEventSource, KinesisEventSource and DynamoEventSource Closes aws#5430
720f0eb
to
5f0c91b
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
Update the README.md with a few lines and a code snippet stating the existence of this method. Nothing big. Sufficient if the snippet shows an example with just one of these event sources.
@@ -67,21 +67,28 @@ export interface EventSourceMappingProps extends EventSourceMappingOptions { | |||
* modify the Lambda's execution role so it can consume messages from the queue. | |||
*/ | |||
export class EventSourceMapping extends cdk.Resource { | |||
/** | |||
* The Ref of the EventSourceMapping |
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.
* The Ref of the EventSourceMapping | |
* The identifier for this EventSourceMapping |
@@ -9,6 +9,8 @@ export interface DynamoEventSourceProps extends StreamEventSourceProps { | |||
* Use an Amazon DynamoDB stream as an event source for AWS Lambda. | |||
*/ | |||
export class DynamoEventSource extends StreamEventSource { | |||
private _eventSourceMappingId: string | undefined = undefined; |
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.
Use ?
to declare optional types. Same in other places.
private _eventSourceMappingId: string | undefined = undefined; | |
private _eventSourceMappingId?: string; |
|
||
this.table.grantStreamRead(target); | ||
} | ||
|
||
/** | ||
* The Ref of the EventSourceMapping |
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.
Update documentation per the other comment in the review
public get eventSourceMappingId(): string | undefined { | ||
return this._eventSourceMappingId; | ||
} |
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 would suggest that we throw an Error
here instead of returning undefined
, with the message 'DynamoEventSource is not yet bound to an event source mapping'.
fn.addEventSource(eventSource); | ||
|
||
// THEN | ||
test.notEqual(eventSource.eventSourceMappingId, undefined); |
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.
Use test.ok()
.
I would even suggest that you test for equality to the event source id that gets returned here - it'll be a cloudformation intrinsic of the form 'Fn::GetAtt: { ... }'.
In case, it starts with 'Token...', use stack.resolve(eventSource.eventSourceMappingId)
to resolve the token and get the CF intrinsic.
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 changed it to test.ok but could you maybe elaborate on how I should check equality of the eventSourceId?
stack.resolve(eventSource.eventSourceMappingId)
returns {Ref: '...'}
where shall I get the id that should be equal to this Ref value?
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.
You cannot. The eventual evenSourceMappingId is generated by cloudformation and our unit tests don't interact with it. You can only check for direct equality with the Ref
string.
/** | ||
* The Ref of the EventSourceMapping | ||
*/ | ||
public get eventSourceMappingId(): string | undefined { |
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.
We should probably define this as a property on IEventSource
so that all future event sources also implement.
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 thought about it, but there are also classes like SnsEventSource
& S3EventSource
& ApiEventSource
that implement the IEventSource
interface and do not have an eventSourceMappingId
.
Should I still add it to the interface?
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
eventSourceMappingId
@eliasdraexler - I pushed some updates to the README. It was easier to change them myself than provide them as comments. Hope you don't mind. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Pull request has been modified.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
1 similar comment
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Commit Message
feat(lambda-event-sources): expose
eventSourceMappingId
(#5689)Exposes the Ref of
AWS::Lambda::EventSourceMapping
as eventSourceMappingId property on the EventSourceMapping and further on the SqsEventSource, KinesisEventSource and DynamoEventSourceCloses #5430
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license