boto3
boto3 copied to clipboard
EC2 object has no attribute KeyPairInfo
Describe the issue
The documentation for boto3 has a section for KeyPairInfo. If you run the example code, it raises an exeption.
ec2 = boto3.client('ec2')
key_pair_info = ec2.KeyPairInfo('test')
Exception:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [99], line 1
----> 1 key_pair_info = ec2.KeyPairInfo('test')
File ~/venv/lib/python3.11/site-packages/botocore/client.py:859, in BaseClient.__getattr__(self, item)
856 if event_response is not None:
857 return event_response
--> 859 raise AttributeError(
860 f"'{self.__class__.__name__}' object has no attribute '{item}'"
861 )
AttributeError: 'EC2' object has no attribute 'KeyPairInfo'
Looking at old issues: here is one that mentions this documentation problem and that someone was looking into fixing it. However, that issue was closed automatically after a period of time.
https://github.com/boto/boto3/issues/1945#issuecomment-492803349
Links
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#keypairinfo
Hi @utkonos, thanks for reaching out.
I was able to reproduce the same behavior and can confirm that it's inconsistent with what the documentation says. I reached out to the EC2 team for further investigation and confirm such behavior. I will post an update here once I hear back from the team.
Best, John
I think the section for KeyPair along with the section for KeyPairInfo need to be fixed.
This line of code in the KeyPair example is correct:
key_pair = ec2.KeyPair('name')
However, this returns a KeyPairInfo object. That object has all the various attributes and methods listed on the KeyPairInfo section. Someone needs to review both of these sections and edit them so that they are correct. As it is now, both are basically wrong/confusing.
Thanks for providing additional inputs. I requested the team to look into both sections and they will hopefully clear up any confusion. Again I will make sure to post an update once I hear back and thank you for being patient with us!
Hi @utkonos - I appreciate your patience while we look into this. I have created a backlog item internally for boto3 team to further investigate. While I wasn't given any timeframe as to when to expect an update, I'll let you know when I receive any updates from them.
P74602266