-
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
StateMachine - support for definition string or JSON #8146
Comments
@erik-telesoftas thanks for logging the issue! I think that's an interesting use case and one that would be useful. I like option for option |
Another motivation point is that AWS have nice support for working with JSON definition, so would be great to have possibility to import it nicely into CDK https://aws.amazon.com/blogs/compute/aws-step-functions-support-in-visual-studio-code/ |
I would also like this feature. My team really only uses CfnStateMachine because it supports the JSON string and VSCode allows you to visualize the state machine definition locally. |
that sounds like a really cool use case for a CDK custom construct. Let me know if you need help with those I build a couple of htose: https://github.com/p6m7g8/awesome-projen#awscdkconstructlibrary , https://martinmueller.dev , Alternatively just ust the hedge feature
|
Wanted to add another voice in favor of this feature, it would be very helpful to our use case. |
there's enough activity on this issue that we'll need to prioritize it soon. @djjolicoeur can you expand on your use case at a high level? I'm trying to aggregate all the desired features to set ourselves up for designing a solution. |
We wanted to add this vote as well to support this feature request; this would be very useful in several projects! |
This would be a very useful feature |
+1 |
+100 |
+1 |
Upvote as well. A little boggled this isn't supported already. Edit to expand on my use case: I'm specifically looking for a way to import JSON from a sfn I've built using the AWS console and use that as the definition for a statemachine that's created and managed via cdk. It's neat that the cdk supports building these things programmatically but the visual designer is just a superior way to deal with the awkward syntax rules these things have, IMHO. |
Need the same thing here. We didn't start with CDK. I'm trying to add it in now that our dev has created the step functions we need in the console. I don't want to re-write 20+ step functions with JS function-chaining. |
+1 |
Would it be possible to add option to use TOKENs in the state machine source string ? |
+1 |
2 similar comments
+1 |
+1 |
+1 on this. Currently I can't see a way of defining a |
+1 as well. I have a state machine defined as YAML and deployed from SAM. I'm looking at moving the project to SAM+CDK, and I'd like to move all of my infrastructure definitions to the Python CDK. I'd love to be able to keep the state machine definition as a standalone text file. |
+1 Would be great to design the workflow in the workflow studio and then just take the JSON and bring it to CDK. This is not a good way for all definitions but for some smaller and straightforward ones it'll be great. |
+1 |
1 similar comment
+1 |
+1
Le lun. 23 mai 2022 à 18:26, Daegon Kim ***@***.***> a écrit :
… +1
—
Reply to this email directly, view it on GitHub
<#8146 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2SZBZU2FSTBZ5BXYZK5GLVLOWS3ANCNFSM4NHOI7QA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
+1 |
1 similar comment
+1 |
As pointed out by @mmuller88 this is a great use case for a CDK custom construct and even better there is already are finished construct available on Construct Hub / GitHub. To install it you can simply use pip with the following command: Simply creating a Step Function from a definition in a json file can be done like this: import mbonig.state_machine
class Your_Stack(Stack):
def __init__(
self, scope: Construct, id: str, **kwargs
) -> None:
super().__init__(scope, id, **kwargs)
with open('sample.json', 'r+', encoding='utf-8') as sample:
sample_dict = json.load(sample)
state_machine = mbonig.state_machine.StateMachine(
self,
'A nice state machine',
definition = sample_dict,
logs= None) But the Construct allows you to also override values from the definition file, so that you can still leverage the AWS CDK as the source of truth for the state machine. For example you could replace the Creating a Step Function from a definition with overwrite looks like this: import mbonig.state_machine
class Your_Stack(Stack):
def __init__(
self, scope: Construct, id: str, **kwargs
) -> None:
super().__init__(scope, id, **kwargs)
with open('sample.json', 'r+', encoding='utf-8') as sample:
sample_dict = json.load(sample)
lambda_arn = str(trigger_lambda.function_arn)
state_machine = mbonig.state_machine.StateMachine(self,
'A nice state machine', definition=sample_dict, logs=None,
overrides={'Trigger Lambda': {'Parameters': {'FunctionName': lambda_arn}}}) I hope this solution is also useful for others:) |
I was able to go around it by defining my own IRuleTarget: Java Example: public class CfnStateMachineTarget implements IRuleTarget {
private CfnStateMachine stateMachine;
private Role role;
public CfnStateMachineTarget(CfnStateMachine stateMachine, Role role) {
this.stateMachine = stateMachine;
this.role = role;
}
@Override
public @NotNull RuleTargetConfig bind(@NotNull IRule rule, @Nullable String id) {
return RuleTargetConfig.builder()
.arn(stateMachine.getAttrArn())
.role(role)
.build();
}
@Override
public @NotNull RuleTargetConfig bind(@NotNull IRule rule) {
return bind(rule, null);
}
} |
In Python I was able to do this: state_machine_cfn = _step.CfnStateMachine(
scope=self,
id=machine_id,
definition_string=definition_string,
role_arn=role.role_arn,
)
schedule_rule = _event.Rule(
scope=self,
id=id,
schedule=schedule,
rule_name=rule_name,
targets=[
_target.SfnStateMachine(
_step.StateMachine.from_state_machine_arn(
scope=self,
id=rule_id,
state_machine_arn=state_machine_cfn.attr_arn,
)
)
],
) In other words, I just create an |
+1 we should not do hacks to solve this, this is common sense... If you give me a lovely AWS Console to diagram step functions and then the result is a json definition why should I be forced to translate that to Code? |
+1 There's also the value of being able to test a step function defined as ASL using StepFunctionsLocal. Now that my colleagues and I have run into this problem, I have realised that I prefer not to entangle business logic (control flow and data flow) expressed in a Step Function in the mechanism used to configure and deploy that functionality. |
This can be achieved with the steps as follows,
|
This change to AWS CDK will allow for the easier design of workflows by using the workflow studio. The visual representation of workflows is more attractive and easier to understand for developers and business people. Additionally, this change will address related issues in the CDK, improving the overall functionality and user experience. Adding the definitionBody and definitionSubstitutions props and the union-like class DefinitionBody will make it easier to define workflows using this tool by allowing users to define workflows in different ways, such as from an external file or a string. Closes #8146 Refs #18880 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
@hoegertn unfortunately your change doesn't update the example in https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.StateMachine.html , which still uses the deprecated |
I see 'definition' marked as deprecated and 'definitionBody' in construct props. |
@infinitedreams9586 I said it does not update the example:
|
Good catch. Will supply a fix asap. |
When creating Step Functions StateMachine there is no possibility to provide already created definition string.
Also there is no way of creating IChainable from definition string of JSON which would also solve the issue.
That would be extremely useful for our use-case, when it is more convenient to define initial flow steps in JSON file and then edit them programmatically.
When using low-level CfnStateMachine there is no way of getting state machine ARN, so workaround is to construct it by hands, also we loose some helpers there.
Use Case
Having possibility to convert IChainable to and from JSON would also help a lot for early state machine testing and debugging.
Proposed Solution
a) Add JSON input support to Chain similar to one we have in CustomState which does accept JSON as input, but works only for single state.
b) Add support for definitionString in StateMachine similar to one we have in CfnStateMachine
c) Add support for definitionJson in StateMachine similar to one we have in CustomState
Other
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: