我正在尝试通过boto3运行Amazon EC2上已经存在的实例。
//! Allows subcomponents to gain access to model component
class CDbMappingComponentAware {
public:
//! Destructor (added for 1st warning)
// virtual ~CDbMappingComponentAware() {}
//! Set the corresponding component
virtual void setMappingComponent(CDbMappingComponent *component);
...
...
但在这一行
df5 = df5.append({'Q':'Q', 'R':'Q', 'S':'Q'}, ignore_index=True)
我收到错误
import sys
import boto3
instance_id = "i-03e7f6391a0f523ee"
action = 'ON'
ec2 = boto3.client('ec2')
if action == 'ON':
response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False)
else:
response = ec2.stop_instances(InstanceIds=[instance_id], DryRun=False)
print(response)
#resp2=ec2.describe_instances()
#foo = response['Reservations'][0]['Instances'][0]['NetworkInterfaces'][0]['Association']['PublicDnsName']
#filter=[{'Name':'Association','Values':['PublicDnsName']}]
#print (foo)
#instance = ec2.resource('ec2').instance(instance_id)
#while instance.state['Name'] not in ('running', 'stopped'):
# sleep(5)
# print("the instance is initializing")
x2=boto3.resource('ec2')
instance=x2.Instance('instance_id')
foo=instance.wait_until_running('self',Filters=[{'Name':'instance-state-name','Values':['running']}])
print ("instance.wait_until_running('self',Filters=[{'Name':'instance-state-name','Values':['running']}]) = "+foo)
这里使用
有什么问题?foo=instance.wait_until_running('self',Filters=[{'Name':'instance-state-name','Values':['running']}])
我只是想了解此处提到的属性如何可用
https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#instance
可以在程序中使用。我无法使用的诸如File "E:\installation2\python3\lib\site-packages\boto3\resources\factory.py", line 369, in do_waiter
waiter(self, *args, **kwargs)
File "E:\installation2\python3\lib\site-packages\boto3\resources\action.py", line 202, in __call__
response = waiter.wait(**params)
File "E:\installation2\python3\lib\site-packages\botocore\waiter.py", line 53, in wait
Waiter.wait(self, **kwargs)
File "E:\installation2\python3\lib\site-packages\botocore\waiter.py", line 313, in wait
last_response=response
botocore.exceptions.WaiterError: Waiter InstanceRunning failed: Invalid id: "instance_id"
之类的方法。
答案 0 :(得分:1)
好,我解决了由于使用
而引起的问题instance=x2.Instance('instance_id')
它应该像这样使用
instance=x2.Instance(instance_id)