Download pem keyfile after create_key_pair

388 views
Skip to first unread message

Neverland

unread,
Dec 16, 2009, 8:36:58 AM12/16/09
to boto-users
Hi,

with boto-1.8d, I was able to write a web application (inside Google
App Engine) that enables me to create key pairs in EC2.

new_key = conn_region.create_key_pair(new_key_name)

Now, I want to download the private key (.pem-file).

When I create a key pair inside the AWS Management Console, a window
appears, asking me what to do with the .pem-file (save, open...). This
is what I want to implement.

Provides boto this functionality?

If not, any ideas how to get this feature?

Best Regards
Christian

Mitchell Garnaat

unread,
Dec 16, 2009, 9:04:26 AM12/16/09
to boto-...@googlegroups.com
Yes, boto allows you to download the .pem file.  Something like this should work:

>>> kp = c.create_key_pair('mynewkp')
>>> kp.save('/Users/mitch/.ssh')

It will download the file and save it as "/Users/mitch/.ssh/mynewkp.pem".  You still need to go tweak the permissions on the file.  I should probably have the save method handle that, as well.

See:

http://boto.s3.amazonaws.com/ref/ec2.html#module-boto.ec2.keypair

for details.

Mitch


--

You received this message because you are subscribed to the Google Groups "boto-users" group.
To post to this group, send email to boto-...@googlegroups.com.
To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.



Neverland

unread,
Dec 16, 2009, 11:23:32 AM12/16/09
to boto-users
Hi Mitchell,

I tried the save() method but it is not working for me. Maybe because
I use the Google App Engine SDK. This is my code:

neuer_key = conn_region.create_key_pair(neuerkeyname)
neuer_key.save("/tmp/tmp.pem")

It leads to this error.

Traceback (most recent call last):
File "/home/bauni/Google_AppEngine/google_appengine/google/appengine/
ext/webapp/__init__.py", line 509, in __call__
handler.post(*groups)
File "/home/bauni/Google_AppEngine/koala2/change.py", line 452, in
post
neuer_key.save("/tmp/tmp.pem")
File "/home/bauni/Google_AppEngine/koala2/boto/ec2/keypair.py", line
82, in save
fp = open(file_path, 'wb')
File "/home/bauni/Google_AppEngine/google_appengine/google/appengine/
tools/dev_appserver.py", line 1116, in __init__
raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: wb

Is there no way to send the pem-file to the browser?

Best Regards,
Christian

Mitchell Garnaat

unread,
Dec 16, 2009, 11:41:34 AM12/16/09
to boto-...@googlegroups.com
Hmm.  After you create the keypair, there is an attribute on the KeyPair object called "material" that contains the data for the PEM file as a string.  Does that help?

Mitch


Best Regards,
  Christian

Luca Mearelli

unread,
Dec 16, 2009, 11:53:28 AM12/16/09
to boto-...@googlegroups.com
On Wed, Dec 16, 2009 at 5:23 PM, Neverland <cr...@unix-ag.uni-kl.de> wrote:
> Hi Mitchell,
>
> I tried the save() method but it is not working for me. Maybe because
> I use the Google App Engine SDK. This is my code:
>
> neuer_key = conn_region.create_key_pair(neuerkeyname)
> neuer_key.save("/tmp/tmp.pem")
>

I think that the problem is just that GAE does not allow writing to
the filesystem, see here:

http://code.google.com/appengine/docs/python/runtime.html#The_Sandbox

you may store the data (e.g. the key material you download with boto)
in the datastore provided by GAE


Luca

Neverland

unread,
Dec 16, 2009, 11:59:06 AM12/16/09
to boto-users
I have tried the material object too.

neuer_key = conn_region.create_key_pair(neuerkeyname)
self.response.out.write(neuer_key.material)

But it helps not very much.
The application workflow is disturbed and the content of the pem-file
is formated ugly.

The best way would be sending the pem-file to the browser, so the user
can choose to download the file or open it with any application.

Best Regards,
Christian

Mitchell Garnaat

unread,
Dec 16, 2009, 12:53:12 PM12/16/09
to boto-...@googlegroups.com
On Wed, Dec 16, 2009 at 11:59 AM, Neverland <cr...@unix-ag.uni-kl.de> wrote:

The best way would be sending the pem-file to the browser, so the user
can choose to download the file or open it with any application.


I have no idea what that means.  Could you explain?
 


Neverland

unread,
Dec 16, 2009, 1:50:49 PM12/16/09
to boto-users
When You create a new key pair in ElasticFox for example a window
appears that asks you what do do with the .pem-file.

You know this "open with/save"-dialog of all web browsers.

I mean this dialog: http://www.oucs.ox.ac.uk/email/webmail/images/moz-dialog.png

Can I realize this with boto + Python + GoogleAppEngine SDK ?

Best Regards,
Christian

mARK bLOORE

unread,
Dec 16, 2009, 2:15:57 PM12/16/09
to boto-...@googlegroups.com
according to the python docs 'wb' is a valid mode, though the 'b' is
ignored if not on windows. so this looks like an app engine bug.


On Wed, Dec 16, 2009 at 11:23 AM, Neverland <cr...@unix-ag.uni-kl.de> wrote:
> --
>
> You received this message because you are subscribed to the Google Groups "boto-users" group.
> To post to this group, send email to boto-...@googlegroups.com.
> To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.
>
>
>



--
mARK bLOORE <mbl...@gmail.com>
Reply all
Reply to author
Forward
0 new messages