启动Spot Insances时出现InvalidTime错误

时间:2016-05-02 04:30:45

标签: amazon-web-services aws-ec2

我正在尝试使用仅在特定日期和时间之前有效的请求启动专色实例,直到特定日期和时间。以下是我的配置。

$request_valid_from = new DateTime();
$request_valid_until = add_time_interval((clone $request_valid_from), 5);

$config = [
                'BlockDurationMinutes' => 60,
                'InstanceCount' => 1,
                'SpotPrice' => strval($this->get_average_spot_price('c3.large)),
                'Type' => 'one-time',

                'LaunchSpecification' => [
                        'EbsOptimized' => false,
                        'InstanceType' => 'c3.large',
                        'ImageId' => AMI_ID,
                    ],
                'ValidFrom' => $request_valid_from,
                'ValidUntil' => $request_valid_until,
            ];

echo($config)

function add_time_interval($current_time, $interval){
        $current_time->modify( '+' .strval($interval) .  ' seconds' );
        return $current_time;
    }

当我打印配置时,我得到以下内容;

"BlockDurationMinutes": 60,
    "InstanceCount": 1,
    "SpotPrice": "0.04592",
    "Type": "one-time",
    "LaunchSpecification": {
        "EbsOptimized": false,
        "InstanceType": "c3.large",
        "ImageId": "ami-b23c22dc"
    },
    "ValidFrom": {
        "date": "2016-05-02 13:11:18.000000",
        "timezone_type": 3,
        "timezone": "Asia\/Tokyo"
    },
    "ValidUntil": {
        "date": "2016-05-02 13:11:23.000000",
        "timezone_type": 3,
        "timezone": "Asia\/Tokyo"
    }

现在,我尝试启动现场实例并收到以下错误。

InvalidTime (client): "Mon May 02 04:28:11 UTC 2016" is an invalid time

错误消息的时间不同。所以,我在this之后设置了正确的imezone。

运行命令date会给出正确的时间(如请求中所示)。我不确定为什么错误消息显示不同的时间。

详细错误消息

06-May-2016 13:40:20 Asia/Tokyo] PHP Fatal error:  Uncaught exception 'Aws\Ec2\Exception\Ec2Exception' with message 'Error executing "RequestSpotInstances" on "https://ec2.ap-northeast-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://ec2.ap-northeast-1.amazonaws.com` resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidTime</Code><Message>"Fri May 06 04:40:19 UT (truncated...)
 InvalidTime (client): "Fri May 06 04:40:19 UTC 2016" is an invalid time - <?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidTime</Code><Message>"Fri May 06 04:40:19 UTC 2016" is an invalid time</Message></Error></Errors><RequestID>efd4458f-e05a-4cb7-8332-4be2dca8c486</RequestID></Response>'

exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://ec2.ap-northeast-1.amazonaws.com` resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidTime</Code><Message>"Fri May 06 04:40:19 UT (trunca in /projects/mv2/millvi-auto-scaling/ec2-manager/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 192

1 个答案:

答案 0 :(得分:0)

代码执行需要一些时间,所以我稍微延迟了request_valid_from(2秒)并且它有效。

$request_valid_from = new DateTime();

//Delay the request slightly (2 seconds)
$request_valid_from = add_time_interval((clone $request_valid_from), 2);

$request_valid_until = add_time_interval((clone $request_valid_from), 10);