Skip to content
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

Can't invoke a state machine from a state machine (nested workflows) #82

Open
smcroskey opened this issue May 20, 2022 · 6 comments
Open
Labels
backlog bug Something isn't working

Comments

@smcroskey
Copy link

I have a simple state machine using the AWS CDK adapter with cdktf where I am trying to use nested workflows via the StepFunctionsStartExecution optimized integration.

        // create child state machine
        const manualReviewStateMachine = new StateMachine(...)

       // in the parent state machine...
        return new sfnTasks.StepFunctionsStartExecution(this.scope, `Manual Review`, {
            stateMachine: manualReviewStateMachine,
            integrationPattern: IntegrationPattern.RUN_JOB,
            input: sfn.TaskInput.fromObject({...})
        })

However, the cdktf JSON output doesn't appear to be valid because the reference to the child state machine uses a Ref attribute that doesn't exist (modified the TF json output slightly to make it more readable, but the key is the "Ref" attribute in the StateMachineArn field value for the Manual Review state):

"Manual Review":{
    "Next": "...",
    "Type": "Task",
    "Resource": join("", "arn:", data.aws_partition.aws-adapter_aws-partition_68D67DE5.partition, ":states:::states:startExecution.sync:2"),
    "Parameters": {
        "Input": { ... },
        "StateMachineArn": jsondecode(aws_cloudcontrolapi_resource.aws-adapter_ParallelComplianceLegalEntityReviewManualReviewStateMachine0B6709C9_D8D91C4C.properties)["Ref"]
    }
}

If I try to deploy, it complains about a missing Ref attribute. Note that if I change the Ref above to Arn and deploy, it deploys successfully. It seems that the StateMachine mapping for the AWS CDK adapter must not be including the Ref attribute?

@smcroskey
Copy link
Author

Based on the above, I was able to work around this issue by deriving from StateMachine and overriding the stateMachineArn property like this:

export class StateMachine extends sfn.StateMachine {
    constructor(scope: Construct, id: string, props: StateMachineProps) {
        super(scope, id, props);
        // @ts-ignore
        this.stateMachineArn = this.getResourceArnAttribute(
            (this.node.defaultChild as CfnStateMachine).attrArn,
            {
                service: 'states',
                resource: 'stateMachine',
                resourceName: this.physicalName,
                arnFormat: ArnFormat.COLON_RESOURCE_NAME,
            }
        )
    }
}

(basically just replacing the resource attribute here from ref to attrArn)

@ansgarm
Copy link
Member

ansgarm commented Jun 2, 2022

Wow, nice detective work here!

I don't know about the specifics that are at play here, but it feels like this could be a difference between CloudFormation and the AWS CloudControl API with the latter not returning a ref attribute while CloudFormation seems to support this. But that is something that should be confirmed first.

We could however, add a special case for state machines and switch from Ref to Arn in this case. The current implementation for resources that are supported by the AWS CC API just passes along, whatever was called.

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Aug 2, 2022
@ansgarm ansgarm removed the stale An issue or pull request that has not been updated in a very long time label Aug 2, 2022
@github-actions
Copy link

github-actions bot commented Oct 2, 2022

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Oct 2, 2022
@ansgarm ansgarm removed the stale An issue or pull request that has not been updated in a very long time label Oct 3, 2022
@github-actions
Copy link

github-actions bot commented Dec 3, 2022

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Dec 3, 2022
@github-actions
Copy link

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen.

@xiehan xiehan reopened this Dec 12, 2022
@xiehan xiehan added backlog and removed stale An issue or pull request that has not been updated in a very long time labels Dec 12, 2022
@xiehan xiehan added the bug Something isn't working label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants