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(aws-lambda-eventbridge) New Construct Implementation & bug fix #368

Merged
merged 10 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .viperlightignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,14 @@ source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/test
source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json:33
# This is a test case
source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/test/test.kinesisstream-gluejob.test.ts:127
# aws-lambda-eventbridge. Auto generated Ids are ignored & x-ray resource permission with a `*` in test cases is ignored
biffgaut marked this conversation as resolved.
Show resolved Hide resolved
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.deployFunction.expected.json:122
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.deployFunctionWithNewEventBus.expected.json:149
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.deployFunctionWithVpc.expected.json:163
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.existingEventBus.expected.json:108
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.existingFunction.expected.json:122
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/aws-lambda-eventbridge.test.ts:68
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/aws-lambda-eventbridge.test.ts:177
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/aws-lambda-eventbridge.test.ts:360
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/aws-lambda-eventbridge.test.ts:368
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/aws-lambda-eventbridge.test.ts:477
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToKinesisFirehoseToS3(stack, 'test-eventbridge-firehose', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
biffgaut marked this conversation as resolved.
Show resolved Hide resolved
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToKinesisStreams(stack, 'test-eventbridge-kinesisstreams', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToLambda(stack, 'test-eventbridge-lambda', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToSns(stack, 'test-eventbridge-sns', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToSqs(stack, 'test-eventbridge-sqs', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventbridgeToStepfunctions(stack, 'test-eventbridge-stepfunctions', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToKinesisFirehoseToS3(stack, 'test-eventsrule-firehose', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToKinesisStreams(stack, 'test-eventsrule-kinesisstreams', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToLambda(stack, 'test-eventsrule-lambda', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToSns(stack, 'test-eventsrule-sns', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToSqs(stack, 'test-eventsrule-sqs', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ test('check exception while passing existingEventBus & eventBusProps', () => {
existingEventBusInterface: new events.EventBus(stack, `test-existing-new-eventbus`, {})
};

try {
const app = () => {
new EventsRuleToStepFunction(stack, 'test-eventsrule-stepfunctions', props);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
};
expect(app).toThrowError();
});

test('check custom event bus resource with props when deploy:true', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib/*.js
test/*.js
*.d.ts
coverage
test/lambda/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lib/*.js
test/*.js
*.js.map
*.d.ts
node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
.nycrc
.LAST_PACKAGE
*.snk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exclude typescript source and config
*.ts
tsconfig.json
coverage
.nyc_output
*.tgz
*.snk
*.tsbuildinfo

# Include javascript files and typescript declarations
!*.js
!*.d.ts

# Exclude jsii outdir
dist

# Include .jsii
!.jsii

# Include .jsii
!.jsii
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# aws-lambda-eventbridge module
<!--BEGIN STABILITY BANNER-->

---

![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge)

---
<!--END STABILITY BANNER-->

| **Reference Documentation**:| <span style="font-weight: normal">https://docs.aws.amazon.com/solutions/latest/constructs/</span>|
|:-------------|:-------------|
<div style="height:8px"></div>

| **Language** | **Package** |
|:-------------|-----------------|
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_lambda_eventbridge`|
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-lambda-eventbridge`|
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.lambdaeventbridge`|

This AWS Solutions Construct implements an AWS Lambda function connected to an Amazon EventBridge.

Here is a minimal deployable pattern definition in Typescript:

``` typescript
import { LambdaToEventbridge, LambdaToEventbridgeProps } from "@aws-solutions-constructs/aws-lambda-eventbridge";

new LambdaToEventbridge(this, 'LambdaToEventbridgePattern', {
lambdaFunctionProps: {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(`${__dirname}/lambda`)
}
});

```

## Initializer

``` text
new LambdaToEventbridge(scope: Construct, id: string, props: LambdaToEventbridgeProps);
```

_Parameters_

* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html)
* id `string`
* props [`LambdaToEventbridgeProps`](#pattern-construct-props)

## Pattern Construct Props

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|An optional, existing Lambda function to be used instead of the default function. Providing both this and `lambdaFunctionProps` will cause an error.|
|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|Optional user-provided properties to override the default properties for the Lambda function. |
|existingEventBusInterface?|[`events.IEventBus`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.IEventBus.html)| Optional user-provided custom EventBus for construct to use. Providing both this and `eventBusProps` results an error.|
|eventBusProps?|[`events.EventBusProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.EventBusProps.html)|Optional user-provided properties to override the default properties when creating a custom EventBus. Setting this value to `{}` will create a custom EventBus using all default properties. If neither this nor `existingEventBusInterface` is provided the construct will use the `default` EventBus. Providing both this and `existingEventBusInterface` results an error.|
|existingVpc?|[`ec2.IVpc`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.IVpc.html)|An optional, existing VPC into which this pattern should be deployed. When deployed in a VPC, the Lambda function will use ENIs in the VPC to access network resources and an Interface Endpoint will be created in the VPC for Amazon EventBridge. If an existing VPC is provided, the `deployVpc` property cannot be `true`. This uses `ec2.IVpc` to allow clients to supply VPCs that exist outside the stack using the [`ec2.Vpc.fromLookup()`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Vpc.html#static-fromwbrlookupscope-id-options) method.|
|vpcProps?|[`ec2.VpcProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.VpcProps.html)|Optional user-provided properties to override the default properties for the new VPC. `enableDnsHostnames`, `enableDnsSupport`, `natGateways` and `subnetConfiguration` are set by the pattern, so any values for those properties supplied here will be overrriden. If `deployVpc` is not `true` then this property will be ignored.|
|deployVpc?|`boolean`|Whether to create a new VPC based on `vpcProps` into which to deploy this pattern. Setting this to true will deploy the minimal, most private VPC to run the pattern:<ul><li> One isolated subnet in each Availability Zone used by the CDK program</li><li>`enableDnsHostnames` and `enableDnsSupport` will both be set to true</li></ul>If this property is `true` then `existingVpc` cannot be specified. Defaults to `false`.|
|eventBusEnvironmentVariableName?|`string`|Optional Name for the EventBus's name environment variable set for the Lambda function.|

## Pattern Properties

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of the Lambda function created by the pattern.|
|eventBus?|[`events.IEventBus`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.IEventBus.html)|Returns the instance of events.IEventBus used by the construct|
|vpc?|[`ec2.IVpc`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.IVpc.html)|Returns an interface on the VPC used by the pattern (if any). This may be a VPC created by the pattern or the VPC supplied to the pattern constructor.|

## Default settings

Out of the box implementation of the Construct without any override will set the following defaults:

### AWS Lambda Function
* Configure limited privilege access IAM role for Lambda function.
* Enable reusing connections with Keep-Alive for NodeJs Lambda function.
* Allow the function to put events to EventBus (custom EventBus can be used by specifying `existingEventBusInterface` or `eventBusProps` property).
* Enable X-Ray Tracing
* Set Environment Variables
* EVENTBUS_NAME
* AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)

## Architecture
![Architecture Diagram](architecture.png)

***
&copy; Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading