-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(lambda-event-sources): expose eventSourceMappingId
#5689
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
Changes from 2 commits
5f0c91b
bde8aff
ebda1b4
0c48311
c4e65d9
b417d46
9102d3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
| constructor(private readonly table: dynamodb.Table, props: DynamoEventSourceProps) { | ||
| super(props); | ||
|
|
||
|
|
@@ -22,10 +24,18 @@ export class DynamoEventSource extends StreamEventSource { | |
| throw new Error(`DynamoDB Streams must be enabled on the table ${this.table.node.path}`); | ||
| } | ||
|
|
||
| target.addEventSourceMapping(`DynamoDBEventSource:${this.table.node.uniqueId}`, | ||
| const eventSourceMapping = target.addEventSourceMapping(`DynamoDBEventSource:${this.table.node.uniqueId}`, | ||
| this.enrichMappingOptions({eventSourceArn: this.table.tableStreamArn}) | ||
| ); | ||
| this._eventSourceMappingId = eventSourceMapping.eventSourceMappingId; | ||
|
|
||
| this.table.grantStreamRead(target); | ||
| } | ||
|
|
||
| /** | ||
| * The Ref of the EventSourceMapping | ||
|
||
| */ | ||
| public get eventSourceMappingId(): string | undefined { | ||
|
||
| return this._eventSourceMappingId; | ||
| } | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,4 +231,46 @@ export = { | |
| test.done(); | ||
| }, | ||
|
|
||
| 'contains eventSourceMappingId after lambda binding'(test: Test) { | ||
| // GIVEN | ||
| const stack = new cdk.Stack(); | ||
| const fn = new TestFunction(stack, 'Fn'); | ||
| const table = new dynamodb.Table(stack, 'T', { | ||
| partitionKey: { | ||
| name: 'id', | ||
| type: dynamodb.AttributeType.STRING | ||
| }, | ||
| stream: dynamodb.StreamViewType.NEW_IMAGE | ||
| }); | ||
| const eventSource = new sources.DynamoEventSource(table, { | ||
| startingPosition: lambda.StartingPosition.TRIM_HORIZON | ||
| }); | ||
|
|
||
| // WHEN | ||
| fn.addEventSource(eventSource); | ||
|
|
||
| // THEN | ||
| test.notEqual(eventSource.eventSourceMappingId, undefined); | ||
|
||
| test.done(); | ||
| }, | ||
|
|
||
| 'eventSourceMappingId is undefined before binding to lambda'(test: Test) { | ||
| // GIVEN | ||
| const stack = new cdk.Stack(); | ||
| const table = new dynamodb.Table(stack, 'T', { | ||
| partitionKey: { | ||
| name: 'id', | ||
| type: dynamodb.AttributeType.STRING | ||
| }, | ||
| stream: dynamodb.StreamViewType.NEW_IMAGE | ||
| }); | ||
| const eventSource = new sources.DynamoEventSource(table, { | ||
| startingPosition: lambda.StartingPosition.TRIM_HORIZON | ||
| }); | ||
|
|
||
| // WHEN/THEN | ||
| test.equal(eventSource.eventSourceMappingId, undefined); | ||
| test.done(); | ||
| }, | ||
|
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
||||||
| * The Ref of the EventSourceMapping | |
| * The identifier for this 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.
Use
?to declare optional types. Same in other places.