简体   繁体   中英

Getting private key from ServiceResource create_key_pair

I know how to obtain the private key of a AWS Key Pair in boto3:

import boto3
client = boto3.client('ec2')
dict_key_pair = client.create_key_pair(KeyName="temp-1")
private_key = dict_key_pair['KeyMaterial']

But I'd prefer to get a EC2.KeyPair instance instead of a dict.

I understand that the way to create such an instance is:

service_resource = boto3.resource('ec2')
entity_key_pair = service_resource.create_key_pair(KeyName="temp-2")

Unfortunately I cannot find out how to extract the private key from the newly created object.

This looks like an issue in how the EC2.KeyPair shape is modeled, specifically for create_key_pair . I opened a GitHub issue to track progress on fixing the issue.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM