Skip to content

Commit

Permalink
added IEventSourceMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Niranjan Jayakar committed Mar 10, 2020
1 parent 303aabb commit c3f4dfe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
28 changes: 25 additions & 3 deletions packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,28 @@ export interface EventSourceMappingOptions {
readonly parallelizationFactor?: number;
}

/**
* Properties for declaring a new event source mapping.
*/
export interface EventSourceMappingProps extends EventSourceMappingOptions {
/**
* The target AWS Lambda function.
*/
readonly target: IFunction;
}

/**
* Represents an event source mapping for a lambda function.
* @see https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventsourcemapping.html
*/
export interface IEventSourceMapping extends cdk.IResource {
/**
* The identifier for this EventSourceMapping
* @attribute
*/
readonly eventSourceMappingId: string;
}

/**
* Defines a Lambda EventSourceMapping resource.
*
Expand All @@ -112,11 +127,18 @@ export interface EventSourceMappingProps extends EventSourceMappingOptions {
* The `SqsEventSource` class will automatically create the mapping, and will also
* modify the Lambda's execution role so it can consume messages from the queue.
*/
export class EventSourceMapping extends cdk.Resource {
export class EventSourceMapping extends cdk.Resource implements IEventSourceMapping {

/**
* The identifier for this EventSourceMapping
* @attribute
* Import an event source into this stack from its event source id.
*/
public static fromEventSourceMappingId(scope: cdk.Construct, id: string, eventSourceMappingId: string): IEventSourceMapping {
class Import extends cdk.Resource implements IEventSourceMapping {
public readonly eventSourceMappingId = eventSourceMappingId;
}
return new Import(scope, id);
}

public readonly eventSourceMappingId: string;

constructor(scope: cdk.Construct, id: string, props: EventSourceMappingProps) {
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
"props-default-doc:@aws-cdk/aws-lambda.CodeConfig.inlineCode",
"props-default-doc:@aws-cdk/aws-lambda.CodeConfig.s3Location",
"docs-public-apis:@aws-cdk/aws-lambda.EventSourceMappingOptions",
"docs-public-apis:@aws-cdk/aws-lambda.EventSourceMappingProps",
"props-default-doc:@aws-cdk/aws-lambda.FunctionAttributes.role",
"props-default-doc:@aws-cdk/aws-lambda.FunctionAttributes.securityGroup",
"props-default-doc:@aws-cdk/aws-lambda.FunctionAttributes.securityGroupId",
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-lambda/test/test.event-source-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,14 @@ export = {
}), /parallelizationFactor must be between 1 and 10 inclusive, got 11/);

test.done();
}
},

'import event source mapping'(test: Test) {
const stack = new cdk.Stack(undefined, undefined, { stackName: 'test-stack' });
const imported = EventSourceMapping.fromEventSourceMappingId(stack, 'imported', '14e0db71-5d35-4eb5-b481-8945cf9d10c2');

test.equals(imported.eventSourceMappingId, '14e0db71-5d35-4eb5-b481-8945cf9d10c2');
test.equals(imported.stack.stackName, 'test-stack');
test.done();
},
};

0 comments on commit c3f4dfe

Please sign in to comment.