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-events-rule-sqs & aws-events-rule-sns): New aws-events-rule-sqs and aws-events-rule-sns pattern implementation #55

Merged
merged 20 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 18 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
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,78 @@
# 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:
gockle marked this conversation as resolved.
Show resolved Hide resolved

``` javascript
const { EventsRuleToSNSTopicProps, EventsRuleToSNSTopic } = require('@aws-solutions-constructs/aws-events-rule-sns');
gockle marked this conversation as resolved.
Show resolved Hide resolved

const props: EventsRuleToSNSTopicProps = {
eventRuleProps: {
schedule: events.Schedule.rate(Duration.minutes(5))
}
};

new EventsRuleToSNSTopic(stack, 'test-events-rule-sns', props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this instead of stack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since stack is a variable and the module does not include a class which extends a construct this wont work here. Let me know if I am missing anything I followed the other integration test patterns?

```

## 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** |
|:-------------|:----------------|-----------------|
|snsTopicProps?|[`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. |
gockle marked this conversation as resolved.
Show resolved Hide resolved
gockle marked this conversation as resolved.
Show resolved Hide resolved
|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. |

## 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

gockle marked this conversation as resolved.
Show resolved Hide resolved
## 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 snsTopicProps?: sns.TopicProps
gockle marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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 0.8.0
gockle marked this conversation as resolved.
Show resolved Hide resolved
* @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.snsTopicProps
});

//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