boto3 で AWS キー ペアのプライベート キーを取得する方法を知っています。
import boto3
client = boto3.client('ec2')
dict_key_pair = client.create_key_pair(KeyName="temp-1")
private_key = dict_key_pair['KeyMaterial']
EC2.KeyPair
しかし、辞書ではなくインスタンスを取得したいと思います。
このようなインスタンスを作成する方法は次のとおりであることを理解しています。
service_resource = boto3.resource('ec2')
entity_key_pair = service_resource.create_key_pair(KeyName="temp-2")
残念ながら、新しく作成されたオブジェクトから秘密鍵を抽出する方法がわかりません。