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-sources): expose eventSourceMappingId #5689

Merged

Conversation

eliasdraexler
Copy link
Contributor

@eliasdraexler eliasdraexler commented Jan 7, 2020

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 DynamoEventSource

Closes #5430


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

@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

…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
@eliasdraexler eliasdraexler force-pushed the eliasdraexler/event-source-mapping-id branch from 720f0eb to 5f0c91b Compare January 7, 2020 14:44
@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

@SomayaB SomayaB added draft pr/work-in-progress This PR is a draft and needs further work. and removed draft labels Jan 7, 2020
@eliasdraexler eliasdraexler marked this pull request as ready for review January 8, 2020 13:38
@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

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Suggested change
* 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;
Copy link
Contributor

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.

Suggested change
private _eventSourceMappingId: string | undefined = undefined;
private _eventSourceMappingId?: string;


this.table.grantStreamRead(target);
}

/**
* The Ref of the EventSourceMapping
Copy link
Contributor

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

Comment on lines 38 to 40
public get eventSourceMappingId(): string | undefined {
return this._eventSourceMappingId;
}
Copy link
Contributor

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);
Copy link
Contributor

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.

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

Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@eliasdraexler eliasdraexler Jan 28, 2020

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?

@mergify mergify bot dismissed nija-at’s stale review January 28, 2020 14:20

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

@nija-at nija-at changed the title feat(lambda-event-sources): add eventSourceMappingId property to Even… feat(lambda-event-sources): expose eventSourceMappingId Feb 26, 2020
nija-at
nija-at previously approved these changes Feb 26, 2020
@nija-at
Copy link
Contributor

nija-at commented Feb 26, 2020

@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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: c4e65d9
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@mergify mergify bot dismissed nija-at’s stale review February 27, 2020 12:12

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: b417d46
  • 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 Feb 27, 2020

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

@mergify
Copy link
Contributor

mergify bot commented Feb 27, 2020

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

@mergify mergify bot merged commit 5ea2679 into aws:master Feb 27, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 9102d3d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 9102d3d
  • 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
pr/work-in-progress This PR is a draft and needs further work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lambda: unable to access event source mapping ID
4 participants