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

(stepfunctions): example for using statemachine versions and aliases with StateMachine construct #26441

Closed
wong-a opened this issue Jul 20, 2023 · 6 comments
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@wong-a
Copy link
Contributor

wong-a commented Jul 20, 2023

Describe the issue

Step Functions supports gradual deployments through versions and aliases. It would be nice to have some examples of how to achieve this in CDK in the stepfunctions module docs.

Example:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';

/**
 * Example CDK stack demonstrating how to achieve gradual deployments
 * for Step Functions using versions and aliases.
 */
export class VersioningCdkExampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // StateMachine
    const stateMachine = new sfn.StateMachine(this, 'myStateMachine', {
      definition: new sfn.Pass(this, 'DefineRepositories', { result: sfn.Result.fromString("version 1") })
    });

    // Version that always points to the latest revision by using `stateMachineRevisionId`
    const version = new sfn.CfnStateMachineVersion(this, 'Version', {
      stateMachineArn: stateMachine.stateMachineArn,
      stateMachineRevisionId: stateMachine.stateMachineRevisionId,
    });

    // When the state machine changes, the CFN does an update replacement of 'Version'
    // To prevent distruption to callers of the previous version, we need to keep it.
    version.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);

    // Alias that gradually shifts 10% of traffic to the new version every minute
    const alias = new sfn.CfnStateMachineAlias(this, 'myAlias', {
      deploymentPreference: {
        type: "LINEAR",
        interval: 1,
        percentage: 10,
        stateMachineVersionArn: version.ref
      }
    })
  }
}

Links

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions-readme.html

@wong-a wong-a added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Jul 20, 2023
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Jul 20, 2023
@wong-a wong-a changed the title (aws_stepfunctions): Add examples of gradual deployments using statemachine versions and aliases (stepfunctions): Add examples of gradual deployments using statemachine versions and aliases Jul 20, 2023
@peterwoodworth
Copy link
Contributor

We don't have any higher level constructs for State Machine Versions or Aliases, so the CloudFormation documentation is considered sufficient in tandem with the existing L2 construct StateMachine.

If we convert this instead to a feature request for supporting higher level constructs for StateMachine Version and Alias, we can do that.

@peterwoodworth peterwoodworth added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 20, 2023
@peterwoodworth peterwoodworth changed the title (stepfunctions): Add examples of gradual deployments using statemachine versions and aliases (stepfunctions): support statemachine versions and aliases in higher level constructs Jul 20, 2023
@peterwoodworth peterwoodworth added feature-request A feature should be added or improved. and removed documentation This is a problem with documentation. labels Jul 20, 2023
@wong-a
Copy link
Contributor Author

wong-a commented Jul 20, 2023

the CloudFormation documentation is considered sufficient in tandem with the existing L2 construct StateMachine.

I disagree. Users benefit from complete code examples and the existing docs don't show how to use all three resources together. If you think that doesn't belong in CDK docs for some reason, we will put that in the Step Functions developer guide: https://docs.aws.amazon.com/step-functions/latest/dg/version-rolling-deployment.html

I don't see a need for higher level constructs for StateMachineVersion or StateMachineAlias at the moment. The only abstraction I'd see happening is extending StateMachine to automatically create versions and aliases similar to AWS::Serverless::StateMachine in SAM.

@peterwoodworth
Copy link
Contributor

If you want a full example involving multiple resources, this would best be added as an example in the examples repo

@peterwoodworth peterwoodworth changed the title (stepfunctions): support statemachine versions and aliases in higher level constructs (stepfunctions): example for using statemachine versions and aliases with StateMachine construct Jul 20, 2023
@peterwoodworth
Copy link
Contributor

I can't transfer this issue to that repo since these repositories live in different orgs, so I'll close this and allow you to duplicate this there if desired.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@wong-a
Copy link
Contributor Author

wong-a commented Jul 20, 2023

My 2¢: Versions and aliases as a fundamental part of deploying state machines safely in a continuous deployment setting. This is why I think there should be a basic example of this in the CDK construct docs, where users first go to learn how to use it.

Happy to move that over to aws-cdk-examples and Step Functions docs if that's a no-no here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants