4

I need to make a call from my website to an EC2 instance with an SSM's SendCommand. As I understand, dumping the result into an S3 bucket is the only option. My command is going to execute for some time (about a minute - two). The interface is supposed to show the 'waiting' state, like an animation of loading. After the completion of running the command on my EC2 I need o show the result of it, which will be dumped into an S3 bucket.

Please, advise on what is the best approach to know when the command running on EC2 is finished on my website.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

1 Answers1

0

Old question but you can capture the commandID to a string when you execute it.

  def ssmCommandId = awsCli([
    cmd: "ssm send-command --instance-ids ${awsInstance} --region \'eu-west-1\' \
      --document-name \'AWS-RunShellScript\' --parameters commands=\"${ssmCommand}\" \
      --output text --query \'Command.CommandId\'",
      returnStdout: true
    ])

You can then use the wait command and pass the commandID from above: https://docs.aws.amazon.com/cli/latest/reference/ssm/wait/command-executed.html

Alternatively, you can write your own loop that polls SSM and retrieves the commandID status

Dave Shaw
  • 97
  • 1
  • 7