在 aws ssm 中使用一次命令 id 后,未调用 Getcommandinvocation

Getcommandinvocation is not being invoked after command id is used once in aws ssm

我正在 asp.net web mvc web 应用程序中实施 aws ssm 发送命令。下面是我的代码。发送命令后,我尝试在 aws ssm 中使用 getcommandinvocation 调用已发送命令的状态。问题是当调试器存在时,这段代码在调试模式下工作正常。但是在发布模式下,它不起作用(当调试器不存在时)。在发布模式下,我收到异常 'invocation does not exist'。我读到当命令 ID 和实例 ID 与任何调用都不匹配时会发生这种情况。所以我怀疑,当调用状态正在进行时,当它返回 do 循环时,命令不会再次被调用,因为它之前被调用过。我不明白我哪里出错了。有人可以帮忙吗?? 感谢任何帮助

      var sendCommandRequest = new SendCommandRequest()
      {
        DocumentName = mdl_AWSCommands.command_name,
        InstanceIds = mdl_AWSCommands.instance_ids,
        Parameters = mdl_AWSCommands.parameter_with_values
      };
      SendCommandResponse sendCommandResponse = new SendCommandResponse();
      sendCommandResponse = client.SendCommand(sendCommandRequest);
      var getCommandInvocationRequest = new GetCommandInvocationRequest()
      {
        CommandId = sendCommandResponse.Command.CommandId,
        InstanceId = sendCommandResponse.Command.InstanceIds[0].ToString()
      };`enter code here`       
      do
      {
        GetCommandInvocationResponse getCommandInvocationResponse = client.GetCommandInvocation(getCommandInvocationRequest);
        strGetCommandInvocationStatus = getCommandInvocationResponse.Status.Value.ToString();
        if (getCommandInvocationResponse.StatusDetails.Contains("Success"))
        {
          if (getCommandInvocationResponse.StandardErrorContent == "")
          {
            
            mdl_AwsCmdOutput.Clear();
            mdl_AwsCmdOutput.Add(new Mdl_AWSCommands
            {
              command_output = getCommandInvocationResponse.StandardOutputContent,
              command_status = "Success",
              invocation_command_id = getCommandInvocationResponse.CommandId.ToString()
            });
            status = true;
            break;
          }
          else
          {
            mdl_AwsCmdOutput.Clear();
            mdl_AwsCmdOutput.Add(new Mdl_AWSCommands
            {
              command_output = getCommandInvocationResponse.StandardErrorContent,
              command_status = "Error",
              invocation_command_id = getCommandInvocationResponse.CommandId.ToString()
            });
            status = true;            
            break;
          }

        }
        else if (getCommandInvocationResponse.Status.Value.Contains("InProgress") || getCommandInvocationResponse.Status.Value.Contains("Pending"))
        {
          status = false;//reviewcomment
          var stopwatch = Stopwatch.StartNew();
          while (true)
          {
            if (stopwatch.ElapsedMilliseconds >= 10000)
            {                                   
              break;
            }
          }
        }
        else if (getCommandInvocationResponse.Status.Value.Contains("Delayed") || getCommandInvocationResponse.Status.Value.Contains("Cancelled") ||
          getCommandInvocationResponse.Status.Value.Contains("TimedOut") || getCommandInvocationResponse.Status.Value.Contains("Failed") ||
          getCommandInvocationResponse.Status.Value.Contains("Cancelling"))
        {
          mdl_AwsCmdOutput.Clear();
          mdl_AwsCmdOutput.Add(new Mdl_AWSCommands
          {
            command_status = getCommandInvocationResponse.Status,
            invocation_command_id = getCommandInvocationResponse.CommandId.ToString()
          });
          status = true;
        }
      } while (status == false);
    }

我通过添加这个解决了这个问题

 var stopwatch = Stopwatch.StartNew();
        while (true)
        {
          if (stopwatch.ElapsedMilliseconds >= 5000)
          {
            break;
          }
        }

在调用 get 命令调用之前。它解决了我的问题。