Create and download an AWS ec2 keypair using pytho

2019-03-28 04:12发布

I'm having difficulty figuring out a way (if possible) to create a new AWS keypair with the Python Boto library and then download that keypair.

1条回答
Evening l夕情丶
2楼-- · 2019-03-28 04:37

The Key object returned by the create_keypair method in boto has a "save" method. So, basically you can do something like this:

>>> import boto
>>> ec2 = boto.connect_ec2()
>>> key = ec2.create_key_pair('mynewkey')
>>> key.save('/path/to/keypair/dir')

If you want a more detailed example, check out https://github.com/garnaat/paws/blob/master/ec2_launch_instance.py.

Does that help? If not, provide some specifics about the problems you are encountering.

查看更多
登录 后发表回答