Skip to content

Commit f57a048

Browse files
committed
Merge branch 'Issue305' of github.com:awslabs/aws-solutions-constructs into Issue305
2 parents 648649d + 7f4308b commit f57a048

37 files changed

+2668
-262
lines changed

.viperlightignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/test/lambda-sqs-
2626
source/patterns/@aws-solutions-constructs/aws-lambda-step-function/test/lambda-step-function.test.ts:129
2727
source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/test/lambda-stepfunctions.test.ts:129
2828
source/patterns/@aws-solutions-constructs/aws-events-rule-sns/test/events-rule-sns-topic.test.ts:243
29+
source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/test/eventbridge-sns-topic.test.ts:243
2930
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:131
3031
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:105
3132
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md:39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/*.js
2+
test/*.js
3+
*.d.ts
4+
coverage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
lib/*.js
2+
test/*.js
3+
*.js.map
4+
*.d.ts
5+
node_modules
6+
*.generated.ts
7+
dist
8+
.jsii
9+
10+
.LAST_BUILD
11+
.nyc_output
12+
coverage
13+
.nycrc
14+
.LAST_PACKAGE
15+
*.snk
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Exclude typescript source and config
2+
*.ts
3+
tsconfig.json
4+
coverage
5+
.nyc_output
6+
*.tgz
7+
*.snk
8+
*.tsbuildinfo
9+
10+
# Include javascript files and typescript declarations
11+
!*.js
12+
!*.d.ts
13+
14+
# Exclude jsii outdir
15+
dist
16+
17+
# Include .jsii
18+
!.jsii
19+
20+
# Include .jsii
21+
!.jsii
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# aws-eventbridge-kinesisfirehose-s3 module
2+
<!--BEGIN STABILITY BANNER-->
3+
4+
---
5+
6+
![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge)
7+
8+
> All classes are under active development and subject to non-backward compatible changes or removal in any
9+
> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model.
10+
> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.
11+
12+
---
13+
<!--END STABILITY BANNER-->
14+
15+
| **Reference Documentation**:| <span style="font-weight: normal">https://docs.aws.amazon.com/solutions/latest/constructs/</span>|
16+
|:-------------|:-------------|
17+
<div style="height:8px"></div>
18+
19+
| **Language** | **Package** |
20+
|:-------------|-----------------|
21+
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_eventbridge_kinesisfirehose_s3`|
22+
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3`|
23+
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.eventbridgekinesisfirehoses3`|
24+
25+
This AWS Solutions Construct implements an Amazon EventBridge Rule to send data to an Amazon Kinesis Data Firehose delivery stream connected to an Amazon S3 bucket.
26+
27+
Here is a minimal deployable pattern definition in Typescript:
28+
29+
``` javascript
30+
import * as cdk from '@aws-cdk/core';
31+
import { EventbridgeToKinesisFirehoseToS3, EventbridgeToKinesisFirehoseToS3Props } from '@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3';
32+
33+
const EventbridgeToKinesisFirehoseToS3Props: EventbridgeToKinesisFirehoseToS3Props = {
34+
eventRuleProps: {
35+
schedule: events.Schedule.rate(cdk.Duration.minutes(5))
36+
}
37+
};
38+
39+
new EventbridgeToKinesisFirehoseToS3(this, 'test-eventbridge-firehose-s3', EventbridgeToKinesisFirehoseToS3Props);
40+
41+
```
42+
43+
## Initializer
44+
45+
``` text
46+
new EventbridgeToKinesisFirehoseToS3(scope: Construct, id: string, props: EventbridgeToKinesisFirehoseToS3Props);
47+
```
48+
49+
_Parameters_
50+
51+
* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html)
52+
* id `string`
53+
* props [`EventbridgeToKinesisFirehoseToS3Props`](#pattern-construct-props)
54+
55+
## Pattern Construct Props
56+
57+
| **Name** | **Type** | **Description** |
58+
|:-------------|:----------------|-----------------|
59+
|eventRuleProps|[`events.RuleProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)|User provided eventRuleProps to override the defaults.|
60+
|kinesisFirehoseProps?|[`kinesisfirehose.CfnDeliveryStreamProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStreamProps.html)|Optional user provided props to override the default props for Kinesis Firehose Delivery Stream|
61+
|existingBucketObj?|[`s3.IBucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.IBucket.html)|Existing instance of S3 Bucket object. If this is provided, then also providing bucketProps is an error. |
62+
|bucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|User provided props to override the default props for the S3 Bucket.|
63+
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroupProps.html)|User provided props to override the default props for for the CloudWatchLogs LogGroup.|
64+
65+
## Pattern Properties
66+
67+
| **Name** | **Type** | **Description** |
68+
|:-------------|:----------------|-----------------|
69+
|eventsRule|[`events.Rule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)|Returns an instance of events.Rule created by the construct.|
70+
|kinesisFirehose|[`kinesisfirehose.CfnDeliveryStream`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html)|Returns an instance of kinesisfirehose.CfnDeliveryStream created by the construct|
71+
|s3Bucket?|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct|
72+
|s3LoggingBucket?|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of s3.Bucket created by the construct as the logging bucket for the primary bucket.|
73+
|eventsRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html)|Returns an instance of the iam.Role created by the construct for Events Rule|
74+
|kinesisFirehoseRole|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html)|Returns an instance of the iam.Role created by the construct for Kinesis Data Firehose delivery stream|
75+
|kinesisFirehoseLogGroup|[`logs.LogGroup`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroup.html)|Returns an instance of the LogGroup created by the construct for Kinesis Data Firehose delivery stream|
76+
77+
## Default settings
78+
79+
Out of the box implementation of the Construct without any override will set the following defaults:
80+
81+
### Amazon EventBridge Rule
82+
* Configure least privilege access IAM role for Amazon EventBridge Rule to publish to the Kinesis Firehose Delivery Stream.
83+
84+
### Amazon Kinesis Firehose
85+
* Enable CloudWatch logging for Kinesis Firehose
86+
* Configure least privilege access IAM role for Amazon Kinesis Firehose
87+
88+
### Amazon S3 Bucket
89+
* Configure Access logging for S3 Bucket
90+
* Enable server-side encryption for S3 Bucket using AWS managed KMS Key
91+
* Turn on the versioning for S3 Bucket
92+
* Don't allow public access for S3 Bucket
93+
* Retain the S3 Bucket when deleting the CloudFormation stack
94+
* Applies Lifecycle rule to move noncurrent object versions to Glacier storage after 90 days
95+
96+
## Architecture
97+
![Architecture Diagram](architecture.png)
98+
99+
***
100+
&copy; Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
14+
import * as events from '@aws-cdk/aws-events';
15+
import * as kinesisfirehose from '@aws-cdk/aws-kinesisfirehose';
16+
import * as defaults from '@aws-solutions-constructs/core';
17+
import * as iam from '@aws-cdk/aws-iam';
18+
import * as s3 from '@aws-cdk/aws-s3';
19+
import * as logs from '@aws-cdk/aws-logs';
20+
import { Construct } from '@aws-cdk/core';
21+
import { overrideProps } from '@aws-solutions-constructs/core';
22+
import { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3';
23+
24+
/**
25+
* @summary The properties for the EventbridgeToKinesisFirehoseToS3 Construct
26+
*/
27+
export interface EventbridgeToKinesisFirehoseToS3Props {
28+
/**
29+
* User provided eventRuleProps to override the defaults
30+
*
31+
* @default - None
32+
*/
33+
readonly eventRuleProps: events.RuleProps
34+
/**
35+
* User provided props to override the default props for the Kinesis Firehose.
36+
*
37+
* @default - Default props are used
38+
*/
39+
readonly kinesisFirehoseProps?: kinesisfirehose.CfnDeliveryStreamProps | any
40+
/**
41+
* Existing instance of S3 Bucket object, providing both this and `bucketProps` will cause an error.
42+
*
43+
* @default - None
44+
*/
45+
readonly existingBucketObj?: s3.IBucket,
46+
/**
47+
* User provided props to override the default props for the S3 Bucket.
48+
*
49+
* @default - Default props are used
50+
*/
51+
readonly bucketProps?: s3.BucketProps,
52+
/**
53+
* User provided props to override the default props for the CloudWatchLogs LogGroup.
54+
*
55+
* @default - Default props are used
56+
*/
57+
readonly logGroupProps?: logs.LogGroupProps
58+
}
59+
60+
export class EventbridgeToKinesisFirehoseToS3 extends Construct {
61+
public readonly eventsRule: events.Rule;
62+
public readonly eventsRole: iam.Role;
63+
public readonly kinesisFirehose: kinesisfirehose.CfnDeliveryStream;
64+
public readonly kinesisFirehoseLogGroup: logs.LogGroup;
65+
public readonly kinesisFirehoseRole: iam.Role;
66+
public readonly s3Bucket?: s3.Bucket;
67+
public readonly s3LoggingBucket?: s3.Bucket;
68+
69+
/**
70+
* @summary Constructs a new instance of the EventbridgeToKinesisFirehoseToS3 class.
71+
* @param {cdk.App} scope - represents the scope for all the resources.
72+
* @param {string} id - this is a a scope-unique id.
73+
* @param {EventbridgeToKinesisFirehoseToS3Props} props - user provided props for the construct
74+
* @access public
75+
*/
76+
constructor(scope: Construct, id: string, props: EventbridgeToKinesisFirehoseToS3Props) {
77+
super(scope, id);
78+
defaults.CheckProps(props);
79+
80+
if (props.existingBucketObj && props.bucketProps) {
81+
throw new Error('Cannot specify both bucket properties and an existing bucket');
82+
}
83+
84+
// Set up the Kinesis Firehose using KinesisFirehoseToS3 construct
85+
const firehoseToS3 = new KinesisFirehoseToS3(this, 'KinesisFirehoseToS3', {
86+
kinesisFirehoseProps: props.kinesisFirehoseProps,
87+
existingBucketObj: props.existingBucketObj,
88+
bucketProps: props.bucketProps,
89+
logGroupProps: props.logGroupProps
90+
});
91+
this.kinesisFirehose = firehoseToS3.kinesisFirehose;
92+
this.s3Bucket = firehoseToS3.s3Bucket;
93+
this.kinesisFirehoseRole = firehoseToS3.kinesisFirehoseRole;
94+
this.s3LoggingBucket = firehoseToS3.s3LoggingBucket;
95+
this.kinesisFirehoseLogGroup = firehoseToS3.kinesisFirehoseLogGroup;
96+
97+
// Create an events service role
98+
this.eventsRole = new iam.Role(this, 'EventsRuleInvokeKinesisFirehoseRole', {
99+
assumedBy: new iam.ServicePrincipal('events.amazonaws.com'),
100+
description: 'Events Rule To Kinesis Firehose Role',
101+
});
102+
103+
// Setup the IAM policy that grants events rule the permission to send cw events data to kinesis firehose
104+
const eventsPolicy = new iam.Policy(this, 'EventsRuleInvokeKinesisFirehosePolicy', {
105+
statements: [new iam.PolicyStatement({
106+
actions: [
107+
'firehose:PutRecord',
108+
'firehose:PutRecordBatch'
109+
],
110+
resources: [this.kinesisFirehose.attrArn]
111+
})
112+
]});
113+
114+
// Attach policy to role
115+
eventsPolicy.attachToRole(this.eventsRole);
116+
117+
// Set up the Kinesis Firehose as the target for event rule
118+
const KinesisFirehoseEventTarget: events.IRuleTarget = {
119+
bind: () => ({
120+
id: '',
121+
arn: this.kinesisFirehose.attrArn,
122+
role: this.eventsRole
123+
})
124+
};
125+
126+
// Set up the events rule props
127+
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([KinesisFirehoseEventTarget]);
128+
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);
129+
130+
this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps);
131+
132+
}
133+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"name": "@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3",
3+
"version": "0.0.0",
4+
"description": "CDK Constructs for Amazon CloudWatch Events Rule to Amazon Kinesis Firehose to Amazon S3 integration.",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/awslabs/aws-solutions-constructs.git",
10+
"directory": "source/patterns/@aws-solutions-constructs/aws-eventbridge-kinesisfirehose-s3"
11+
},
12+
"author": {
13+
"name": "Amazon Web Services",
14+
"url": "https://aws.amazon.com",
15+
"organization": true
16+
},
17+
"license": "Apache-2.0",
18+
"scripts": {
19+
"build": "tsc -b .",
20+
"lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .",
21+
"lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .",
22+
"test": "jest --coverage",
23+
"clean": "tsc -b --clean",
24+
"watch": "tsc -b -w",
25+
"integ": "cdk-integ",
26+
"integ-assert": "cdk-integ-assert",
27+
"integ-no-clean": "cdk-integ --no-clean",
28+
"jsii": "jsii",
29+
"jsii-pacmak": "jsii-pacmak",
30+
"build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert",
31+
"snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert"
32+
},
33+
"jsii": {
34+
"outdir": "dist",
35+
"targets": {
36+
"java": {
37+
"package": "software.amazon.awsconstructs.services.eventbridgekinesisfirehoses3",
38+
"maven": {
39+
"groupId": "software.amazon.awsconstructs",
40+
"artifactId": "eventbridgekinesisfirehoses3"
41+
}
42+
},
43+
"dotnet": {
44+
"namespace": "Amazon.Constructs.AWS.EventbridgeKinesisFirehoseS3",
45+
"packageId": "Amazon.Constructs.AWS.EventbridgeKinesisFirehoseS3",
46+
"signAssembly": true,
47+
"iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png"
48+
},
49+
"python": {
50+
"distName": "aws-solutions-constructs.aws-eventbridge-kinesis-firehose-s3",
51+
"module": "aws_solutions_constructs.aws_eventbridge_kinesis_firehose_s3"
52+
}
53+
}
54+
},
55+
"dependencies": {
56+
"@aws-cdk/aws-iam": "0.0.0",
57+
"@aws-cdk/aws-kinesisfirehose": "0.0.0",
58+
"@aws-cdk/aws-events": "0.0.0",
59+
"@aws-cdk/core": "0.0.0",
60+
"@aws-cdk/aws-s3": "0.0.0",
61+
"@aws-cdk/aws-logs": "0.0.0",
62+
"@aws-solutions-constructs/core": "0.0.0",
63+
"@aws-solutions-constructs/aws-kinesisfirehose-s3": "0.0.0",
64+
"constructs": "^3.2.0"
65+
},
66+
"devDependencies": {
67+
"@aws-cdk/assert": "0.0.0",
68+
"@types/jest": "^26.0.22",
69+
"@types/node": "^10.3.0"
70+
},
71+
"jest": {
72+
"moduleFileExtensions": [
73+
"js"
74+
],
75+
"coverageReporters": [
76+
"text",
77+
[
78+
"lcov",
79+
{
80+
"projectRoot": "../../../../"
81+
}
82+
]
83+
]
84+
},
85+
"peerDependencies": {
86+
"@aws-cdk/aws-iam": "0.0.0",
87+
"@aws-cdk/aws-kinesisfirehose": "0.0.0",
88+
"@aws-cdk/aws-events": "0.0.0",
89+
"@aws-cdk/aws-s3": "0.0.0",
90+
"@aws-cdk/core": "0.0.0",
91+
"@aws-solutions-constructs/core": "0.0.0",
92+
"@aws-solutions-constructs/aws-kinesisfirehose-s3": "0.0.0",
93+
"constructs": "^3.2.0",
94+
"@aws-cdk/aws-logs": "0.0.0"
95+
},
96+
"keywords": [
97+
"aws",
98+
"cdk",
99+
"awscdk",
100+
"AWS Solutions Constructs",
101+
"Amazon EventBridge",
102+
"Amazon Kinesis Data Firehose",
103+
"Amazon S3"
104+
]
105+
}

0 commit comments

Comments
 (0)