AWS SDK中的runInstances()在成功启动实例

时间:2016-04-07 01:53:42

标签: amazon-web-services amazon-ec2 aws-php-sdk

关注this后,我使用了runInstances方法,如下所示启动和实例:

$new_instance_config = array(
            'DryRun' => false,
            'ImageId' => AMI_ID,
            'MinCount' => 1,
            'MaxCount' => 1,
            'InstanceType' => 't1.micro',
            'Placement' => array(
                'AvailabilityZone' => AVAILABILITY_ZONE,
            ),
            'Monitoring' => array(
                'Enabled' => false,
            ),
            'NetworkInterfaces' => array(
                array(
                    'SubnetId' => SUBNET_ID,
                    'DeviceIndex' => 0,
                    'AssociatePublicIpAddress' => true,
                    'DeleteOnTermination' => true,
                    'Groups' => unserialize(SECURITY_GROUP_IDS)
                )
            )
        );

$res = $this->ec2Client->runInstances($new_instance_config);
echo json_encode($res);

然而,这只会打印空白对象{},即使我登录AWS控制台,我也可以看到实例已启动。

我需要访问一些信息,例如已启动实例的AMI ID。我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

请参阅Modeled Responses

尝试:

$res['Instances']

$res->get('Instances')