boto3错误:对象没有属性

时间:2017-05-05 06:33:09

标签: python amazon-web-services boto3

执行简单代码时出错

#!/usr/bin/pyhon

import boto3

ec2 = boto3.resource('ec2')
res = ec2.describe_instances()
  

追踪(最近一次通话):     文件" ec2.py",第6行,in     res = ec2.describe_instances()     AttributeError:' ec2.ServiceResource'对象没有属性' describe_instances'

任何人都可以解释同一错误的确切原因。如何使以下链接中描述的所有方法都能正常工作

https://botocore.readthedocs.io/en/latest/reference/services/ec2.html

以下是我的测试enviormnet中安装的aws版本

  

aws --version   aws-cli / 1.11.83 Python / 2.7.9 Linux / 3.19.0-79-generic botocore / 1.5.46

1 个答案:

答案 0 :(得分:0)

boto3中,资源是围绕API调用的高级包装器。要直接访问API方法,请将boto3.resource('ec2')更改为boto3.client('ec2')