-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iot): add action to start Step Functions State Machine (#26059)
Add new IoT topic rule action to send IoT messages to Step Functions State Machines. Closes #17698. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
15 changed files
with
960 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
packages/@aws-cdk/aws-iot-actions-alpha/lib/step-functions-state-machine-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,65 @@ | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
import * as iot from '@aws-cdk/aws-iot-alpha'; | ||
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions'; | ||
import { CommonActionProps } from './common-action-props'; | ||
import { singletonActionRole } from './private/role'; | ||
import { ArnFormat, Stack } from 'aws-cdk-lib'; | ||
|
||
/** | ||
* Configuration properties of an action for the Step Functions State Machine. | ||
*/ | ||
export interface StepFunctionsStateMachineActionProps extends CommonActionProps { | ||
/** | ||
* Name of the state machine execution prefix. | ||
* The name given to the state machine execution consists of this prefix followed by a UUID. Step Functions creates a unique name for each state machine execution if one is not provided. | ||
* | ||
* @see https://docs.aws.amazon.com/iot/latest/developerguide/stepfunctions-rule-action.html#stepfunctions-rule-action-parameters | ||
* | ||
* @default: None - Step Functions creates a unique name for each state machine execution if one is not provided. | ||
*/ | ||
readonly executionNamePrefix?: string; | ||
} | ||
|
||
/** | ||
* The action to put the record from an MQTT message to the Step Functions State Machine. | ||
*/ | ||
export class StepFunctionsStateMachineAction implements iot.IAction { | ||
private readonly executionNamePrefix?: string; | ||
private readonly role?: iam.IRole; | ||
|
||
/** | ||
* @param stateMachine The Step Functions Start Machine which shoud be executed. | ||
* @param props Optional properties to not use default | ||
*/ | ||
constructor(private readonly stateMachine: stepfunctions.IStateMachine, props?: StepFunctionsStateMachineActionProps) { | ||
this.executionNamePrefix = props?.executionNamePrefix; | ||
this.role = props?.role; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public _bind(rule: iot.ITopicRule): iot.ActionConfig { | ||
const role = this.role ?? singletonActionRole(rule); | ||
const stateMachineName = Stack.of(this.stateMachine).splitArn(this.stateMachine.stateMachineArn, ArnFormat.COLON_RESOURCE_NAME).resourceName; | ||
|
||
if (!stateMachineName) { | ||
throw new Error(`No state machine name found in ARN: '${this.stateMachine.stateMachineArn}'`); | ||
} | ||
|
||
role.addToPrincipalPolicy(new iam.PolicyStatement({ | ||
actions: ['states:StartExecution'], | ||
resources: [this.stateMachine.stateMachineArn], | ||
})); | ||
|
||
return { | ||
configuration: { | ||
stepFunctions: { | ||
stateMachineName, | ||
executionNamePrefix: this.executionNamePrefix, | ||
roleArn: role.roleArn, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
packages/@aws-cdk/aws-iot-actions-alpha/rosetta/default.ts-fixture
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
1 change: 1 addition & 0 deletions
1
...ns-alpha/test/step-functions/integ.step-functions-start-state-machine.js.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":"32.0.0"} |
12 changes: 12 additions & 0 deletions
12
...alpha/test/step-functions/integ.step-functions-start-state-machine.js.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,12 @@ | ||
{ | ||
"version": "32.0.0", | ||
"testCases": { | ||
"state-machine-integtest/DefaultTest": { | ||
"stacks": [ | ||
"test-step-functions-start-state-machine-action-stack" | ||
], | ||
"assertionStack": "state-machine-integtest/DefaultTest/DeployAssert", | ||
"assertionStackName": "statemachineintegtestDefaultTestDeployAssert1FAFBF55" | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...ha/test/step-functions/integ.step-functions-start-state-machine.js.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,135 @@ | ||
{ | ||
"version": "32.0.0", | ||
"artifacts": { | ||
"test-step-functions-start-state-machine-action-stack.assets": { | ||
"type": "cdk:asset-manifest", | ||
"properties": { | ||
"file": "test-step-functions-start-state-machine-action-stack.assets.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"test-step-functions-start-state-machine-action-stack": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "test-step-functions-start-state-machine-action-stack.template.json", | ||
"validateOnSynth": false, | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", | ||
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", | ||
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2a9785d0602d38f259eb92a63ba9ecfd1092a72904af9e5e265db24a5d7a78ab.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", | ||
"additionalDependencies": [ | ||
"test-step-functions-start-state-machine-action-stack.assets" | ||
], | ||
"lookupRole": { | ||
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", | ||
"requiresBootstrapStackVersion": 8, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"dependencies": [ | ||
"test-step-functions-start-state-machine-action-stack.assets" | ||
], | ||
"metadata": { | ||
"/test-step-functions-start-state-machine-action-stack/TopicRule/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRule40A4EA44" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/TopicRule/TopicRuleActionRole/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRole246C4F77" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/TopicRule/TopicRuleActionRole/DefaultPolicy/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "TopicRuleTopicRuleActionRoleDefaultPolicy99ADD687" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/SM/Role/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "SMRole49C19C48" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/SM/Resource": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "SM934E715A" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/BootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "BootstrapVersion" | ||
} | ||
], | ||
"/test-step-functions-start-state-machine-action-stack/CheckBootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "CheckBootstrapVersion" | ||
} | ||
] | ||
}, | ||
"displayName": "test-step-functions-start-state-machine-action-stack" | ||
}, | ||
"statemachineintegtestDefaultTestDeployAssert1FAFBF55.assets": { | ||
"type": "cdk:asset-manifest", | ||
"properties": { | ||
"file": "statemachineintegtestDefaultTestDeployAssert1FAFBF55.assets.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"statemachineintegtestDefaultTestDeployAssert1FAFBF55": { | ||
"type": "aws:cloudformation:stack", | ||
"environment": "aws://unknown-account/unknown-region", | ||
"properties": { | ||
"templateFile": "statemachineintegtestDefaultTestDeployAssert1FAFBF55.template.json", | ||
"validateOnSynth": false, | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", | ||
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", | ||
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", | ||
"requiresBootstrapStackVersion": 6, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", | ||
"additionalDependencies": [ | ||
"statemachineintegtestDefaultTestDeployAssert1FAFBF55.assets" | ||
], | ||
"lookupRole": { | ||
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", | ||
"requiresBootstrapStackVersion": 8, | ||
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" | ||
} | ||
}, | ||
"dependencies": [ | ||
"statemachineintegtestDefaultTestDeployAssert1FAFBF55.assets" | ||
], | ||
"metadata": { | ||
"/state-machine-integtest/DefaultTest/DeployAssert/BootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "BootstrapVersion" | ||
} | ||
], | ||
"/state-machine-integtest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ | ||
{ | ||
"type": "aws:cdk:logicalId", | ||
"data": "CheckBootstrapVersion" | ||
} | ||
] | ||
}, | ||
"displayName": "state-machine-integtest/DefaultTest/DeployAssert" | ||
}, | ||
"Tree": { | ||
"type": "cdk:tree", | ||
"properties": { | ||
"file": "tree.json" | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...tate-machine.js.snapshot/statemachineintegtestDefaultTestDeployAssert1FAFBF55.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": "32.0.0", | ||
"files": { | ||
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { | ||
"source": { | ||
"path": "statemachineintegtestDefaultTestDeployAssert1FAFBF55.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
36 changes: 36 additions & 0 deletions
36
...te-machine.js.snapshot/statemachineintegtestDefaultTestDeployAssert1FAFBF55.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,36 @@ | ||
{ | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...tate-machine.js.snapshot/test-step-functions-start-state-machine-action-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": "32.0.0", | ||
"files": { | ||
"2a9785d0602d38f259eb92a63ba9ecfd1092a72904af9e5e265db24a5d7a78ab": { | ||
"source": { | ||
"path": "test-step-functions-start-state-machine-action-stack.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "2a9785d0602d38f259eb92a63ba9ecfd1092a72904af9e5e265db24a5d7a78ab.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
Oops, something went wrong.