I'm following the example of some other code that has been written. The code in question looks like this:
if virtualname == "ebs":
if deviceSize == None:
deviceSize = 8
if delOnTerminate == None or delOnTerminate == "true":
DOT = "true"
else:
DOT = "false"
lc.BlockDeviceMappings.append(ec2.EBSBlockDeviceMapping(
DeviceName=blockname,
Ebs=ec2.EBSBlockDevice(VolumeSize=deviceSize,
DeleteOnTermination=DOT)))
else:
lc.BlockDeviceMappings.append(ec2.BlockDeviceMapping(DeviceName=blockname,
VirtualName=virtualname))
The AttributeError
happens only when you have a class (in this case a module) and refer to an attribute that doesn't exist. It is like a NameError
but for attributes of objects.
You have imported a module like import ... as ec2
. The module marked ...
does not have a function called EBSBlockDeviceMapping
, so when you call it in your code, it gives an AttributeError
.
Here is what works:
lc.BlockDeviceMappings.append(ec2.BlockDeviceMapping(
DeviceName = blockname,
Ebs=ec2.EBSBlockDevice(
VolumeSize = deviceSize,
DeleteOnTermination = DOT
)
)
)
As pointed out by Reticality, EBSBlockDeviceMapping does not exist. Instead, I just needed to use BlockDeviceMapping and the ec2.EBSBlockDevice takes care of the EBS setup.
Oh yeah, and the argument for DOT needs to be a boolean and not a string so use 'DOT = False' and 'DOT = True' rather than 'DOT = "false"' and 'DOT = "true"'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.