Skip to content

Commit

Permalink
feat(aws-events-rule-sqs & aws-events-rule-sns): New aws-events-rule-…
Browse files Browse the repository at this point in the history
…sqs and aws-events-rule-sns pattern implementation (#55)

* Initial commit for the pattern aws-events-rule-sns

* changes to the implementation of the constructs and tests

* Changing iam policies for the event rule to sns

* Committing integration tests

* Adding README.md

* Adding README.md

* Adding README.md

* Adding new construct aws-events-rule-sqs

* modifying event rule target for sns

* Removing references to lambda in the stack references

* Adding unit tests

* Adding the integration tests

* Fixing integration testing issues

* Removing unnecessary snapshot files

* Adding architecture diagrams

* Removing redundant configurations in .gitignore and .eslintignore

* Code Review

* Code review comments
  • Loading branch information
gockle authored Sep 8, 2020
1 parent 179679d commit 0397579
Show file tree
Hide file tree
Showing 24 changed files with 1,917 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/*.js
test/*.js
*.d.ts
coverage
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-events-rule-sns module
<!--BEGIN STABILITY BANNER-->

---

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

> All classes are under active development and subject to non-backward compatible changes or removal in any
> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model.
> 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.
---
<!--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_events_rule_sns`|
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-events-rule-sns`|
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.eventsrulesns`|

This AWS Solutions Construct implements an AWS Events rule and an AWS SNS Topic.

Here is a minimal deployable pattern definition:

``` typescript
import { EventsRuleToSNSTopicProps, EventsRuleToSNSTopic } from "@aws-solutions-constructs/aws-events-rule-sns";

const props: EventsRuleToSNSTopicProps = {
eventRuleProps: {
schedule: events.Schedule.rate(Duration.minutes(5)),
},
topicsProps: {
displayName: 'event-rule-sns'
}
};

new EventsRuleToSNSTopic(this, 'test-events-rule-sns', props);
```

## Initializer

``` text
new EventsRuleToSNSTopic(scope: Construct, id: string, props: EventsRuleToSNSTopicProps);
```

_Parameters_

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

## Pattern Construct Props

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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. |
|existingTopicObj?|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Existing instance of SNS Topic object, if this is set then the topicProps is ignored.|
|topicProps?|[`sns.TopicProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.TopicProps.html)|User provided props to override the default props for the SNS Topic. |


## Pattern Properties

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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|
|snsTopic|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of sns.Topic created by the construct|

## Default settings

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

### Amazon CloudWatch Events Rule
* Grant least privilege permissions to CloudWatch Events to publish to the SNS Topic

### Amazon SNS Topic
* Configure least privilege access permissions for SNS Topic
* Enable server-side encryption forSNS Topic using AWS managed KMS Key
* Enforce encryption of data in transit

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

***
&copy; Copyright 2020 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

import * as sns from '@aws-cdk/aws-sns';
import * as events from '@aws-cdk/aws-events';
import * as defaults from '@aws-solutions-constructs/core';
import { Construct } from '@aws-cdk/core';
import { overrideProps } from '@aws-solutions-constructs/core';
import { ArnPrincipal } from '@aws-cdk/aws-iam';

export interface EventsRuleToSNSTopicProps {
/**
* User provided props to override the default props for the SNS Topic.
*
* @default - Default props are used
*/
readonly topicsProps?: sns.TopicProps
/**
* User provided eventRuleProps to override the defaults
*
* @default - None
*/
readonly eventRuleProps: events.RuleProps
/**
* Existing instance of SNS Topic object, if this is set then topicProps is ignored.
*
* @default - Default props are used
*/
readonly existingTopicObj?: sns.Topic,
}

export class EventsRuleToSNSTopic extends Construct {
public readonly snsTopic: sns.Topic;
public readonly eventsRule: events.Rule;


/**
* @summary Constructs a new instance of the EventRuleToSns class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {EventsRuleToSNSTopicProps} props - user provided props for the construct.
* @since 1.61.1
* @access public
*/
constructor(scope: Construct, id: string, props: EventsRuleToSNSTopicProps) {
super(scope, id);

//Setup the sns topic.
[this.snsTopic] = defaults.buildTopic(this, {
existingTopicObj: props.existingTopicObj,
topicProps: props.topicsProps
});

//Setup the event rule target as sns topic.
const topicEventTarget: events.IRuleTarget = {
bind: () => ({
id: this.snsTopic.topicName,
arn: this.snsTopic.topicArn
})
}

//Setup up the event rule property.
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([topicEventTarget]);
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);

//Setup up the event rule.
this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps);

//Setup up the grant policy for event to be able to publish to the sns topic.
this.snsTopic.grantPublish(new ArnPrincipal(this.eventsRule.ruleArn))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@aws-solutions-constructs/aws-events-rule-sns",
"version": "1.61.1",
"description": "CDK Constructs for deploying AWS Events Rule that invokes AWS SNS",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc -b .",
"lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .",
"lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .",
"test": "jest --coverage",
"clean": "tsc -b --clean",
"watch": "tsc -b -w",
"integ": "cdk-integ",
"integ-no-clean": "cdk-integ --no-clean",
"integ-assert": "cdk-integ-assert",
"jsii": "jsii",
"jsii-pacmak": "jsii-pacmak",
"build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert",
"snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert"
},
"repository": {
"type": "git",
"url": "https://github.com/awslabs/aws-solutions-constructs.git",
"directory": "source/patterns/@aws-solutions-constructs/aws-events-rule-sns"
},
"author": {
"name": "Amazon Web Services",
"url": "https://aws.amazon.com",
"organization": true
},
"license": "Apache-2.0",
"jsii": {
"outdir": "dist",
"targets": {
"java": {
"package": "software.amazon.awsconstructs.services.eventsrulesns",
"maven": {
"groupId": "software.amazon.awsconstructs",
"artifactId": "eventsrulesns"
}
},
"dotnet": {
"namespace": "Amazon.Constructs.AWS.EventsRuleSns",
"packageId": "Amazon.Constructs.AWS.EventsRuleSns",
"signAssembly": true,
"iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png"
},
"python": {
"distName": "aws-solutions-constructs.aws-events-rule-sns",
"module": "aws_solutions_constructs.aws_events_rule_sns"
}
}
},
"dependencies": {
"@aws-cdk/aws-events": "~1.61.1",
"@aws-cdk/aws-iam": "~1.61.1",
"@aws-cdk/aws-sns": "~1.61.1",
"@aws-cdk/core": "~1.61.1",
"@aws-solutions-constructs/core": "~1.61.1",
"constructs": "^3.0.4"
},
"devDependencies": {
"@aws-cdk/assert": "~1.61.1",
"@types/jest": "^24.0.23",
"@types/node": "^10.3.0"
},
"jest": {
"moduleFileExtensions": [
"js"
]
},
"peerDependencies": {
"@aws-cdk/aws-sns": "~1.61.1",
"@aws-cdk/core": "~1.61.1",
"@aws-cdk/aws-events": "~1.61.1",
"@aws-cdk/aws-iam": "~1.61.1",
"@aws-cdk/aws-kms": "~1.61.1",
"@aws-solutions-constructs/core": "~1.61.1",
"constructs": "^3.0.4"
}
}
Loading

0 comments on commit 0397579

Please sign in to comment.