按照下面的分步说明创建状态机。单击各个步骤编号可展开相应部分。

  • 使用 AWS Step Functions 控制台创建状态机

    要创建状态机,您需要使用 AWS Step Functions 控制台。Step Functions 是一项 Web 服务,让您能够使用可视化工作流来协调分布式应用程序组件和微服务。当状态机已经运行并达到 Task 状态时,系统将调用 Lambda 函数。

    针对此项目,状态机执行下列任务:

    • 创建 AppStream 2.0 映像生成器。
    • 获取 AppStream 2.0 映像生成器和队列的状态。
    • 发送流式传输 URL。
    • 获取 AppStream 2.0 映像名称。
    • 创建 AppStream 队列和堆栈,并将队列与堆栈关联起来。
    • 停止 AppStream 2.0 队列和映像生成器。
     

    要创建状态机,请按下列步骤操作:

    1. 通过以下网址打开 AWS Step Functions 控制台:https://console.aws.amazon.com/states/
    2. 执行以下任一操作:
      • 如果您尚未创建任何状态机函数,系统将会显示入门页面。选择入门,然后选择状态机
      • 如果您已经创建了状态机函数,请在状态机页面的右上角选择创建状态机
    3. 定义状态机页面上,选中使用代码段创作
    4. 类型部分,选中标准
    5. 状态机定义部分,删除占位符代码,并在编辑窗口中粘贴以下代码。
    {
      "StartAt": "Create Image Builder",
      "States": {
        "Create Image Builder": {
          "Type": "Task",
          "Resource":
          "arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_createimagebuilder",
          "ResultPath": "$.type",
          "Next": "Resource Created?"
        },
        "Resource Created?": {
          "Type": "Choice",
          "Choices": [
            {
              "Variable": "$.type",
              "NumericEquals": -1,
              "Next": "Creation Failed"
            },
            {
              "Variable": "$.type",
              "NumericEquals": 1,
              "Next": "Sleep"
            },
            {
              "Variable": "$.type",
              "NumericEquals": 2,
              "Next": "Sleep"
            }
          ],
          "Default": "Sleep"
        },      
        "Sleep": {
          "Type": "Wait",
          "Seconds": 300,
          "Next": "Get Status"
        }, 
        "Get Status": {
          "Type": "Task",
          "Resource":
          "arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_getstatus",
          "Next": "Instance Status",
          "ResultPath": "$.status"
        },
        "Instance Status": {
          "Type": "Choice",
          "Choices": [
            {
              "Variable": "$.status",
              "NumericEquals": -1,
              "Next": "Creation Failed"
            },    
            {
              "Variable": "$.status",
              "NumericEquals": 1,
              "Next": "Send StreamingURL"
            }
          ],
          "Default": "Sleep"
        },   
        "Send StreamingURL": {
          "Type": "Task",
          "Resource":
          "arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_sendstreamingurl",
          "Next": "Split",
          "ResultPath": "$.status"      
        },
        "Split": {
            "Type": "Choice",
          "Choices": [
            {
              "Variable": "$.type",
              "NumericEquals": 1,
              "Next": "Wait For Snapshot"
            },
            {
              "Variable": "$.type",
              "NumericEquals": 2,
              "Next": "1 Hour Timer"
            }
          ],
          "Default": "1 Hour Timer"
        }, 
        "Wait For Snapshot": {
          "Type": "Wait",
          "Seconds": 1500,
          "Next": "IB Status"
        },  
        "IB Status": {
            "Type": "Task",
            "Resource":"arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_getstatus",
            "ResultPath": "$.status",
            "Next": "Snapshotting?"
        },  
        "Snapshotting?": {
          "Type": "Choice",
          "Choices": [
            {
              "Variable": "$.status",
              "NumericEquals": 2,
              "Next": "Get ImageName"
            },
            {
              "Variable": "$.status",
              "NumericEquals": 3,
              "Next": "Get ImageName"
            }
          ],
          "Default": "Wait For Snapshot"
        },   
        "Get ImageName": {
          "Type": "Task",
          "Resource":"arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_getimagename",
          "ResultPath": "$.imagename",
          "Next": "Wait For ImageReady"
        }, 
        "Wait For ImageReady": {
          "Type": "Wait",
          "Seconds": 300,
          "Next": "Image Status"
        },
        "Image Status": {
          "Type": "Task",
          "Resource":"arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_getstatus",
          "ResultPath": "$.status",
          "Next": "ImageReady?"
        },
        "ImageReady?": {
          "Type": "Choice",
          "Choices": [
            {
              "Variable": "$.status",
              "NumericEquals": 3,
              "Next": "Create Fleet"
            }
          ],
          "Default": "Wait For ImageReady"
        },
        "Create Fleet": {
          "Type": "Task",
          "Resource":"arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_createfleet",
          "ResultPath": "$.type",
          "Next": "Resource Created?"
        },
        "1 Hour Timer": {
          "Type": "Wait",
          "Seconds": 3600,
          "Next": "StopResources"
        },  
        "Creation Failed": {
          "Type": "Fail",
          "Cause": "Process Failed",
          "Error": "Process Failed"
        },    
        "StopResources": {
          "Type": "Task",
          "Resource":
          "arn:aws:lambda:<REGION-CODE>:<AWS-ACCOUNT-ID>:function:examplecorp_eao_stopresources",
          "End": true
        }
      }
    }  
    

     6.使用您自己的值替换以下内容:

          • 将 <AWS-ACCOUNT-ID> 替换为您的 AWS 账号。

          • 将 <REGION-CODE> 替换为您选择的 AWS 区域。此值必须全部使用小写。

     7.选择 下一步
     
     8.对于 名称,输入 examplecorp_eao
     
     9.在 权限部分,选择 选择现有角色
     
     10.在 现有角色下拉列表中选择 examplecorp_eao_role,也就是你在模块 2 中创建的 IAM 角色。
     
     11.选择 创建状态机
     
     12.在页面顶部,在 详细信息部分,将显示状态机的 ARN。记下该 ARN 。该 ARN 将在之后的项目中用到,其格式为 arn:aws:states:<REGION-CODE>:<AWS_ACCOUNT-ID>:stateMachine:<STATE-MACHINE-NAME>