A Step Function state machine construct focused on working well with the Workflow Studio
Project description
Workflow Studio compatible State Machine
This is a Workflow Studio compatible AWS Step Function state machine construct.
The goal of this construct is to make it easy to build and maintain your state machines using the Workflow Studio but still leverage the AWS CDK as the source of truth for the state machine.
Read more about it here.
How to Use This Construct
Start by designing your initial state machine using the Workflow Studio. When done with your first draft, copy and paste the ASL definition to a local file.
Create a new instance of this construct, handing it a fully parsed version of the ASL.
Then add overridden values.
The fields in the overrides
field should match the States
field of the ASL.
Examples
const secret = new Secret(stack, 'Secret', {});
new StateMachine(stack, 'Test', {
stateMachineName: 'A nice state machine',
definition: JSON.parse(fs.readFileSync(path.join(__dirname, 'sample.json'), 'utf8').toString()),
overrides: {
'Read database credentials secret': {
Parameters: {
SecretId: secret.secretArn,
},
},
},
});
You can also override nested states in arrays, for example:
new StateMachine(stack, 'Test', {
stateMachineName: 'A-nice-state-machine',
overrides: {
Branches: [{
// pass an empty object too offset overrides
}, {
StartAt: 'StartInstances',
States: {
StartInstances: {
Parameters: {
InstanceIds: ['INSTANCE_ID'],
},
},
},
}],
},
stateMachineType: StateMachineType.STANDARD,
definition: {
States: {
Branches: [
{
StartAt: 'ResumeCluster',
States: {
'Redshift Pass': {
Type: 'Pass',
End: true,
},
},
},
{
StartAt: 'StartInstances',
States: {
'StartInstances': {
Type: 'Task',
Parameters: {
InstanceIds: [
'MyData',
],
},
Resource: 'arn:aws:states:::aws-sdk:ec2:startInstances',
Next: 'DescribeInstanceStatus',
},
'DescribeInstanceStatus': {
Type: 'Task',
Next: 'EC2 Pass',
Parameters: {
InstanceIds: [
'MyData',
],
},
Resource: 'arn:aws:states:::aws-sdk:ec2:describeInstanceStatus',
},
'EC2 Pass': {
Type: 'Pass',
End: true,
},
},
},
],
},
},
});
For Python, be sure to use a context manager when opening your JSON file.
- You do not need to
str()
the dictionary object you supply as yourdefinition
prop. - Elements of your override path do need to be strings.
secret = Secret(stack, 'Secret')
with open('sample.json', 'r+', encoding='utf-8') as sample:
sample_dict = json.load(sample)
state_machine = StateMachine(
self,
'Test',
definition = sample_dict,
overrides = {
"Read database credentials secret": {
"Parameters": {
"SecretId": secret.secret_arn,
},
},
})
In this example, the ASL has a state called 'Read database credentials secret' and the SecretId parameter is overridden with a CDK generated value. Future changes can be done by editing, debugging, and testing the state machine directly in the Workflow Studio. Once everything is working properly, copy and paste the ASL back to your local file.
Issues
Please open any issues you have on Github.
Contributing
Please submit PRs from forked repositories if you'd like to contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mbonig.state-machine-0.0.14.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4d8225f4276cb8e16b4cb78f985419dc9f6adf232d59a9f826e79182aee03dc |
|
MD5 | e2478c7b67c14db9a49829a0d011121a |
|
BLAKE2b-256 | 24248cd787f7a9f6d34311520f69c2fc20bfc7e1af67bab9c183ae9a345d9ad5 |
Hashes for mbonig.state_machine-0.0.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41cf72edebc0e43f69e4e1349cb2c40c635b5cc95711316c362eaea657beb8f8 |
|
MD5 | dca9b60e362cd52e852d657131d7bab6 |
|
BLAKE2b-256 | 00fb9341cc336edb897f68b6be79d5f752898581c456f210ee0e978b2e6f72d4 |