Skip to content

Commit e86c532

Browse files
authored
Merge branch 'main' into feature/aws-iot-sqs
2 parents e782f4a + f50cbbc commit e86c532

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4603
-340
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib/*.js
2+
test/*.js
3+
*.d.ts
4+
coverage
5+
test/lambda/index.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
lib/*.js
2+
test/*.js
3+
!test/lambda/*
4+
*.js.map
5+
*.d.ts
6+
node_modules
7+
*.generated.ts
8+
dist
9+
.jsii
10+
11+
.LAST_BUILD
12+
.nyc_output
13+
coverage
14+
.nycrc
15+
.LAST_PACKAGE
16+
*.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,91 @@
1+
# aws-eventbridge-stepfunctions 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_stepfunctions`|
22+
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) Typescript|`@aws-solutions-constructs/aws-eventbridge-stepfunctions`|
23+
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.eventbridgestepfunctions`|
24+
25+
This AWS Solutions Construct implements an AWS Events rule and an AWS Step Functions State Machine
26+
27+
Here is a minimal deployable pattern definition in Typescript:
28+
29+
``` javascript
30+
const { EventbridgeToStepfunctions, EventbridgeToStepfunctionsProps } from '@aws-solutions-constructs/aws-eventbridge-stepfunctions';
31+
32+
const startState = new stepfunctions.Pass(this, 'StartState');
33+
34+
const props: EventbridgeToStepfunctionsProps = {
35+
stateMachineProps: {
36+
definition: startState
37+
},
38+
eventRuleProps: {
39+
schedule: events.Schedule.rate(Duration.minutes(5))
40+
}
41+
};
42+
43+
new EventbridgeToStepfunctions(stack, 'test-eventbridge-stepfunctions-stack', props);
44+
```
45+
46+
## Initializer
47+
48+
``` text
49+
new EventbridgeToStepfunctions(scope: Construct, id: string, props: EventbridgeToStepfunctionsProps);
50+
```
51+
52+
_Parameters_
53+
54+
* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html)
55+
* id `string`
56+
* props [`EventbridgeToStepfunctionsProps`](#pattern-construct-props)
57+
58+
## Pattern Construct Props
59+
60+
| **Name** | **Type** | **Description** |
61+
|:-------------|:----------------|-----------------|
62+
|stateMachineProps|[`sfn.StateMachineProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachineProps.html)|Optional user provided props to override the default props for sfn.StateMachine|
63+
|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|
64+
|createCloudWatchAlarms|`boolean`|Whether to create recommended CloudWatch alarms|
65+
|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.|
66+
67+
## Pattern Properties
68+
69+
| **Name** | **Type** | **Description** |
70+
|:-------------|:----------------|-----------------|
71+
|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|
72+
|stateMachine|[`sfn.StateMachine`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachine.html)|Returns an instance of sfn.StateMachine created by the construct|
73+
|stateMachineLogGroup|[`logs.ILogGroup`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.ILogGroup.html)|Returns an instance of the ILogGroup created by the construct for StateMachine|
74+
|cloudwatchAlarms?|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct|
75+
76+
## Default settings
77+
78+
Out of the box implementation of the Construct without any override will set the following defaults:
79+
80+
### Amazon CloudWatch Events Rule
81+
* Grant least privilege permissions to CloudWatch Events to trigger the Lambda Function
82+
83+
### AWS Step Function
84+
* Enable CloudWatch logging for API Gateway
85+
* Deploy best practices CloudWatch Alarms for the Step Function
86+
87+
## Architecture
88+
![Architecture Diagram](architecture.png)
89+
90+
***
91+
&copy; Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 sfn from '@aws-cdk/aws-stepfunctions';
15+
import * as events from '@aws-cdk/aws-events';
16+
import * as defaults from '@aws-solutions-constructs/core';
17+
import * as iam from '@aws-cdk/aws-iam';
18+
import { Construct } from '@aws-cdk/core';
19+
import { overrideProps } from '@aws-solutions-constructs/core';
20+
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
21+
import * as logs from '@aws-cdk/aws-logs';
22+
23+
/**
24+
* @summary The properties for the EventbridgeToStepfunctions Construct
25+
*/
26+
export interface EventbridgeToStepfunctionsProps {
27+
/**
28+
* User provided StateMachineProps to override the defaults
29+
*
30+
* @default - None
31+
*/
32+
readonly stateMachineProps: sfn.StateMachineProps,
33+
/**
34+
* User provided eventRuleProps to override the defaults
35+
*
36+
* @default - None
37+
*/
38+
readonly eventRuleProps: events.RuleProps,
39+
/**
40+
* Whether to create recommended CloudWatch alarms
41+
*
42+
* @default - Alarms are created
43+
*/
44+
readonly createCloudWatchAlarms?: boolean,
45+
/**
46+
* User provided props to override the default props for the CloudWatchLogs LogGroup.
47+
*
48+
* @default - Default props are used
49+
*/
50+
readonly logGroupProps?: logs.LogGroupProps
51+
}
52+
53+
export class EventbridgeToStepfunctions extends Construct {
54+
public readonly stateMachine: sfn.StateMachine;
55+
public readonly stateMachineLogGroup: logs.ILogGroup;
56+
public readonly eventsRule: events.Rule;
57+
public readonly cloudwatchAlarms?: cloudwatch.Alarm[];
58+
59+
/**
60+
* @summary Constructs a new instance of the EventbridgeToStepfunctions class.
61+
* @param {cdk.App} scope - represents the scope for all the resources.
62+
* @param {string} id - this is a a scope-unique id.
63+
* @param {EventbridgeToStepfunctionsProps} props - user provided props for the construct
64+
* @access public
65+
*/
66+
constructor(scope: Construct, id: string, props: EventbridgeToStepfunctionsProps) {
67+
super(scope, id);
68+
defaults.CheckProps(props);
69+
70+
[this.stateMachine, this.stateMachineLogGroup] = defaults.buildStateMachine(this, props.stateMachineProps,
71+
props.logGroupProps);
72+
73+
// Create an IAM role for Events to start the State Machine
74+
const eventsRole = new iam.Role(this, 'EventsRuleRole', {
75+
assumedBy: new iam.ServicePrincipal('events.amazonaws.com')
76+
});
77+
78+
// Grant the start execution permission to the Events service
79+
this.stateMachine.grantStartExecution(eventsRole);
80+
81+
// Setup the Events target
82+
const stateMachine: events.IRuleTarget = {
83+
bind: () => ({
84+
id: '',
85+
arn: this.stateMachine.stateMachineArn,
86+
role: eventsRole
87+
})
88+
};
89+
90+
// Defaults props for the Events
91+
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([stateMachine]);
92+
// Override the defaults with the user provided props
93+
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);
94+
// Create the Events Rule for the State Machine
95+
this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps);
96+
97+
if (props.createCloudWatchAlarms === undefined || props.createCloudWatchAlarms) {
98+
// Deploy best practices CW Alarms for State Machine
99+
this.cloudwatchAlarms = defaults.buildStepFunctionCWAlarms(this, this.stateMachine);
100+
}
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"name": "@aws-solutions-constructs/aws-eventbridge-stepfunctions",
3+
"version": "0.0.0",
4+
"description": "CDK Constructs for deploying AWS Events Rule that invokes AWS Step Functions",
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-stepfunctions"
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-no-clean": "cdk-integ --no-clean",
27+
"integ-assert": "cdk-integ-assert",
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.eventbridgestepfunctions",
38+
"maven": {
39+
"groupId": "software.amazon.awsconstructs",
40+
"artifactId": "eventbridgestepfunctions"
41+
}
42+
},
43+
"dotnet": {
44+
"namespace": "Amazon.Constructs.AWS.EventbridgeStepfunctions",
45+
"packageId": "Amazon.Constructs.AWS.EventbridgeStepfunctions",
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-stepfunctions",
51+
"module": "aws_solutions_constructs.aws_eventbridge_stepfunctions"
52+
}
53+
}
54+
},
55+
"dependencies": {
56+
"@aws-cdk/aws-stepfunctions": "0.0.0",
57+
"@aws-cdk/aws-stepfunctions-tasks": "0.0.0",
58+
"@aws-cdk/core": "0.0.0",
59+
"@aws-cdk/aws-events": "0.0.0",
60+
"@aws-cdk/aws-iam": "0.0.0",
61+
"@aws-cdk/aws-lambda": "0.0.0",
62+
"@aws-cdk/aws-logs": "0.0.0",
63+
"@aws-cdk/aws-cloudwatch": "0.0.0",
64+
"@aws-solutions-constructs/core": "0.0.0",
65+
"constructs": "^3.2.0"
66+
},
67+
"devDependencies": {
68+
"@aws-cdk/assert": "0.0.0",
69+
"@types/jest": "^26.0.22",
70+
"@types/node": "^10.3.0"
71+
},
72+
"jest": {
73+
"moduleFileExtensions": [
74+
"js"
75+
],
76+
"coverageReporters": [
77+
"text",
78+
[
79+
"lcov",
80+
{
81+
"projectRoot": "../../../../"
82+
}
83+
]
84+
]
85+
},
86+
"peerDependencies": {
87+
"@aws-cdk/aws-stepfunctions": "0.0.0",
88+
"@aws-cdk/core": "0.0.0",
89+
"@aws-cdk/aws-events": "0.0.0",
90+
"@aws-cdk/aws-iam": "0.0.0",
91+
"@aws-solutions-constructs/core": "0.0.0",
92+
"constructs": "^3.2.0",
93+
"@aws-cdk/aws-lambda": "0.0.0",
94+
"@aws-cdk/aws-cloudwatch": "0.0.0",
95+
"@aws-cdk/aws-stepfunctions-tasks": "0.0.0",
96+
"@aws-cdk/aws-logs": "0.0.0"
97+
},
98+
"keywords": [
99+
"aws",
100+
"cdk",
101+
"awscdk",
102+
"AWS Solutions Constructs",
103+
"Amazon EventBridge",
104+
"AWS Step Functions"
105+
]
106+
}

0 commit comments

Comments
 (0)