本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
示例:Step Functions 中的版本与别名功能部署
下面的金丝雀部署技术示例展示了如何使用 Amazon Command Line Interface部署新的状态机版本。在此示例中,您创建的别名将 20% 的执行流量路由到新版本。然后将剩余的 80% 路由到早期版本。要部署新的状态机版本并使用别名转移执行流量,请完成以下步骤:
- 
             
                从当前状态机修订版中发布一个版本。使用 Amazon CLI 中的 publish-state-machine-version 命令,从名为 myStateMachine:aws stepfunctions publish-state-machine-version --state-machine-arn arn:aws:states:region:account-id:stateMachine:myStateMachine响应会返回发布版本的 stateMachineVersionArn。例如arn:aws:states:。region:account-id:stateMachine:myStateMachine:1
- 
             
                创建指向状态机版本的别名。使用 create-state-machine-alias 命令创建指向 myStateMachinePRODaws stepfunctions create-state-machine-alias --name PROD --routing-configuration "[{\"stateMachineVersionArn\":\"arn:aws:states:region:account-id:stateMachine:myStateMachine:1\",\"weight\":100}]"
- 
             
                验证由别名启动的执行是否使用正确的已发布版本。通过在 start-execution 命令中提供别名 PROD的 ARN 来启动myStateMachineaws stepfunctions start-execution --state-machine-arn arn:aws:states:region:account-id:stateMachineAlias:myStateMachine:PROD --input "{}"如果您在StartExecution请求中提供了状态机 ARN,则它会使用最新的revision状态机而不是您的别名中指定的版本来开始执行。 
- 
             
                更新状态机定义并发布新版本。更新 myStateMachinepublish参数:aws stepfunctions update-state-machine --state-machine-arn arn:aws:states:region:account-id:stateMachine:myStateMachine--definition $UPDATED_STATE_MACHINE_DEFINITION --publish响应会返回新版本的 stateMachineVersionArn。例如arn:aws:states:。region:account-id:stateMachine:myStateMachine:2
- 
             
                更新别名以指向两个版本并设置别名的路由配置。使用 update-state-machine-alias 命令更新别名 PROD的路由配置。配置别名,使 80% 的执行流量流向版本 1,其余 20% 流向版本 2:aws stepfunctions update-state-machine-alias --state-machine-alias-arn arn:aws:states:region:account-id:stateMachineAlias:myStateMachine:PROD --routing-configuration "[{\"stateMachineVersionArn\":\"arn:aws:states:region:account-id:stateMachine:myStateMachine:1\",\"weight\":80}, {\"stateMachineVersionArn\":\"arn:aws:states:region:account-id:stateMachine:myStateMachine:2\",\"weight\":20}]"
- 
             
                将版本 1 替换为版本 2。在验证新的状态机版本能够正常运行后,您可以部署新的状态机版本。为此,请再次更新别名,将 100% 的执行流量分配给新版本。 使用 update-state-machine-alias 命令设置别名 PROD的路由配置,为版本 2 分配 100% 的流量:aws stepfunctions update-state-machine-alias --state-machine-alias-arn arn:aws:states:region:account-id:stateMachineAlias:myStateMachine:PROD --routing-configuration "[{\"stateMachineVersionArn\":\"arn:aws:states:region:account-id:stateMachine:myStateMachine:2\",\"weight\":100}]"
提示
要回滚版本 2 的部署,请编辑别名的路由配置,将 100% 的流量转移到新部署的版本。
aws stepfunctions update-state-machine-alias --state-machine-alias-arn arn:aws:states:region:account-id:stateMachineAlias:myStateMachine:PROD --routing-configuration "[{\"stateMachineVersionArn\":\"arn:aws:states:region:account-id:stateMachine:myStateMachine:1\",\"weight\":100}]"
您可以使用版本与别名功能来执行其他类型的部署。例如,您可以对状态机的新版本进行滚动部署。为此,请在指向新版本的别名的路由配置中,逐渐增加加权百分比。
您也可以使用版本与别名功能来执行蓝绿部署。为此,请创建一个名为 green 的别名,且该别名运行状态机的当前版本 1。然后,创建另一个名为 blue 的别名,运行新版本,例如 2blue 别名发送执行流量。当您确信自己的新版本可以正常运行时,更新 green 别名以指向您的新版本。