-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(iot): add topic rule action for step functions state machine execution #21780
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5c9336
feat(iot): TopicRule action for Step Functions
fab-siciliano 7a113bb
Fix build breaking stack declaration
fab-siciliano bc831e9
Fix build breaking stack declaration
fab-siciliano 1c16d5b
Merge branch 'main' of https://github.com/fab-siciliano/aws-cdk
fab-siciliano 294a019
Merge branch 'main' into main
fab-siciliano fcaf56c
Merge branch 'main' into main
fab-siciliano 1ded35d
Merge branch 'main' of https://github.com/fab-siciliano/aws-cdk
fab-siciliano 52e6dbc
fix build breaking
fab-siciliano 5ef1d35
Merge branch 'main' into main
mergify[bot] 1318142
Merge branch 'main' into main
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/@aws-cdk/aws-iot-actions/lib/step-functions-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as iot from '@aws-cdk/aws-iot'; | ||
import * as sfn from '@aws-cdk/aws-stepfunctions'; | ||
import { CommonActionProps } from './common-action-props'; | ||
import { singletonActionRole } from './private/role'; | ||
|
||
/** | ||
* Configuration properties of an action for Step Functions | ||
*/ | ||
export interface StepFunctionsActionProps extends CommonActionProps { | ||
/** | ||
* Specifies which prefix to append to the state machine execution. | ||
* | ||
* @default - no prefix | ||
*/ | ||
readonly executionNamePrefix?: string; | ||
} | ||
|
||
/** | ||
* The action to start the execution of a Step Functions state machine | ||
*/ | ||
export class StepFunctionsAction implements iot.IAction { | ||
private readonly role?: iam.IRole; | ||
private readonly stateMachine: sfn.StateMachine; | ||
private readonly executionNamePrefix?: string; | ||
|
||
/** | ||
* @param stateMachine The Step Functions state machine whose execution will be started. | ||
* @param props Optional properties to not use default | ||
*/ | ||
constructor( | ||
stateMachine: sfn.StateMachine, | ||
props: StepFunctionsActionProps = {}, | ||
) { | ||
this.stateMachine = stateMachine; | ||
this.role = props.role; | ||
this.executionNamePrefix = props.executionNamePrefix; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
_bind(topicRule: iot.ITopicRule): iot.ActionConfig { | ||
const role = this.role ?? singletonActionRole(topicRule); | ||
role.addToPrincipalPolicy( | ||
new iam.PolicyStatement({ | ||
actions: ['states:StartExecution'], | ||
resources: [this.stateMachine.stateMachineArn], | ||
}), | ||
); | ||
|
||
return { | ||
configuration: { | ||
stepFunctions: { | ||
roleArn: role.roleArn, | ||
stateMachineName: this.stateMachine.stateMachineName, | ||
executionNamePrefix: this.executionNamePrefix, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/@aws-cdk/aws-iot-actions/test/stepfunctions/integ.stepfunctions-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as iot from '@aws-cdk/aws-iot'; | ||
import * as sfn from '@aws-cdk/aws-stepfunctions'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as actions from '../../lib'; | ||
|
||
const app = new cdk.App(); | ||
|
||
class TestStack extends cdk.Stack { | ||
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const topicRule = new iot.TopicRule(this, 'TopicRule', { | ||
sql: iot.IotSql.fromStringAsVer20160323("SELECT * FROM 'device/+/data'"), | ||
}); | ||
|
||
const stateMachine = new sfn.StateMachine(this, 'StateMachine', { | ||
definition: new sfn.Pass(this, 'StartPass'), | ||
}); | ||
|
||
topicRule.addAction(new actions.StepFunctionsAction(stateMachine)); | ||
} | ||
} | ||
|
||
new TestStack(app, 'test-stack'); | ||
app.synth(); |
1 change: 1 addition & 0 deletions
1
...ctions-action.integ.snapshot/IntegrationTestDefaultTestDeployAssertDDDAF29A.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
...s/@aws-cdk/aws-iot-actions/test/stepfunctions/stepfunctions-action.integ.snapshot/cdk.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"20.0.0"} |
11 changes: 11 additions & 0 deletions
11
...aws-cdk/aws-iot-actions/test/stepfunctions/stepfunctions-action.integ.snapshot/integ.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "20.0.0", | ||
"testCases": { | ||
"IntegrationTest/DefaultTest": { | ||
"stacks": [ | ||
"test-stack" | ||
], | ||
"assertionStack": "IntegrationTest/DefaultTest/DeployAssert" | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...-cdk/aws-iot-actions/test/stepfunctions/stepfunctions-action.integ.snapshot/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"version": "20.0.0", | ||
"artifacts": { | ||
"Tree": { | ||
"type": "cdk:tree", | ||
"properties": { | ||
"file": "tree.json" | ||
} | ||
}, | ||
"test-stack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "test-stack.template.json", | ||
"validateOnSynth": false | ||
}, | ||
"metadata": { | ||
"/test-stack/TopicRule/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRule40A4EA44" | ||
} | ||
], | ||
"/test-stack/TopicRule/TopicRuleActionRole/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRole246C4F77" | ||
} | ||
], | ||
"/test-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" | ||
} | ||
], | ||
"/test-stack/StateMachine/Role/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "StateMachineRoleB840431D" | ||
} | ||
], | ||
"/test-stack/StateMachine/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "StateMachine2E01A3A5" | ||
} | ||
], | ||
"/test-stack/Service-principalMap": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "ServiceprincipalMap" | ||
} | ||
] | ||
}, | ||
"displayName": "test-stack" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...iot-actions/test/stepfunctions/stepfunctions-action.integ.snapshot/test-stack.assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "20.0.0", | ||
"files": { | ||
"33ea9644d18ddb62bc89360ac3bad439c89f0f9665650f0548bd2f3106d02783": { | ||
"source": { | ||
"path": "test-stack.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "33ea9644d18ddb62bc89360ac3bad439c89f0f9665650f0548bd2f3106d02783.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed this before, but as a new test, this needs to use the
IntegTest
construct and then run it with the--update-on-failed
flag.