0

I'm trying to get through the eventual consistency of a spot instance so I can assign it within my application. Here's what I've seen, from a fairly simple spot instance call.

The instance requested is immediately started (fast 15-30 second instance running state), but the waiter continues indefinitely.

I'm not sure if the issue lies with my code, the SDK, or AWS not fulfilling the request quickly.

$spotEc2Client = $this->sdk->createEc2([]);

// Create instance via spot request
$result        = $spotEc2Client->requestSpotInstances($spotConfig);
$spotResult    = $result->getPath('SpotInstanceRequests');
$spotRequestId = $spotResult[0]['SpotInstanceRequestId'];

$now = date("F d, Y H:i:s A");
echo "Spot Request ID is: $spotRequestId\n";
echo "Starting at $now MST\n";
$spotEc2Client->waitUntil(
    'SpotInstanceRequestFulfilled',
    [
        'SpotInstanceRequestId' => $spotRequestId,
        '@waiter' => [
            'before' => function (CommandInterface $command, $attempts) {
                $now = date("H:i:s");
                printf(
                    "[$now] About to send %s. Attempt %d\n",
                    $command->getName(),
                    $attempts
                );
            }
        ],
    ]
);

Output:

Spot Request ID is: sir-<my request id>
Starting at August 18, 2017 10:10:20 AM MST
[10:10:20] About to send DescribeSpotInstanceRequests. Attempt 1
[10:10:21] About to send DescribeSpotInstanceRequests. Attempt 2
[10:10:36] About to send DescribeSpotInstanceRequests. Attempt 3
[10:10:52] About to send DescribeSpotInstanceRequests. Attempt 4
[10:11:07] About to send DescribeSpotInstanceRequests. Attempt 5
[10:11:23] About to send DescribeSpotInstanceRequests. Attempt 6
[10:11:38] About to send DescribeSpotInstanceRequests. Attempt 7

Comparing the check times against the launch time:

spot instance launch time

I'm thinking I need to just do my own polling against describeInstances looking specifically for spot instances that are at running or init, and handle it on my own - because the call to DescribeSpotInstanceRequests goes on indefinitely as far as I've been able to tell.

1 Answers1

0

I had misformatted my argument for the SpotRequestId. This was quickly and kindly pointed out to me by someone on AWS PHP SDK's github!

The formatting of my spot instance request required a plural and an array as an argument.

$spotEc2Client->waitUntil(
    'SpotInstanceRequestFulfilled',
    [
        'SpotInstanceRequestId' => $spotRequestId,
    ]
    ...

To Be:

$spotEc2Client->waitUntil(
    'SpotInstanceRequestFulfilled',
    [
        'SpotInstanceRequestIds' => [
            $spotRequestId
    ]
    ...

I think as an API user I would prefer an exception or maybe a warning for the incorrect argument but that's a discussion for another place.