2

如果我部署一个带有 s3 和 api 网关的静态网站,有没有办法让 step 函数等待一些活动,然后将该静态网站上的用户重定向到另一个?

4

1 回答 1

0

我们可以做朋友,

这可以使用 Job Status Poller 模式实现,但稍作调整。如果“工作”是部署网站,那么“完成工作”的条件是看到一些活动进入(理想情况下通过 cloudwatch 指标)。

一旦您看到足够的指标可以满足您的部署,您可以向 webapp 发出推送通知以通知它重定向(使用调用 SNS 的 lambda 函数 - 如在等待计时器示例中)或让 webapp 轮询执行状态直到完成。

下面我发布了 Job Status Poller 的一个非常简单的变体来说明我的示例:

部署完成时发送 SNS

{
  "Comment": "A state machine that publishes to SNS after a deployment completes.",
  "StartAt": "StartDeployment",
  "States": {
    "StartDeployment": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:012345678912:function:KickOffDeployment",
      "ResultPath": "$.guid",
      "Next": "CheckIfDeploymentComplete"
    },
    "CheckIfDeploymentComplete": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:012345678912:function:CheckIfDeploymentComplete",
      "Next": "TriggerWebAppRefresh",
      "InputPath": "$.guid",
      "ResultPath": "$.status",
      "Retry": [ {
         "ErrorEquals": [ "INPROGRESS" ],
         "IntervalSeconds": 5,
         "MaxAttempts": 240,
         "BackoffRate": 1.0
       } ],
       "Catch": [ {
            "ErrorEquals": ["FAILED"],
            "Next": "DeploymentFailed"
       }]
    },
    "DeploymentFailed": {
      "Type": "Fail",
      "Cause": "Deployment failed",
      "Error": "Deployment FAILED"
    },
    "TriggerWebAppRefresh": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-east-1:012345678912:function:SendSNSToWebapp",
      "InputPath": "$.guid",
      "End": true
    }
  }
}
于 2018-02-07T00:59:15.307 回答