【问题标题】:Boto3: Difference between (EC2)KeyPair and KeyPairInfoBoto3:(EC2)KeyPair和KeyPairInfo之间的区别
【发布时间】:2017-10-19 07:51:30
【问题描述】:

谁能指出 Boto3(resource-level) KeyPairKeypairInfo 对象的目的是什么?文档又是模糊的..

import boto3
ec2 = boto3.resource('ec2')
key_pair = ec2.KeyPair('name')
key_pair = ec2.KeyPairInfo('name')

重要的是,KeyPairInfo 根本不起作用:AttributeError: 'ec2.ServiceResource' object has no attribute 'KeyPairInfo'

另外:

  • 两者都无法创建新的密钥对,那我们为什么还要拥有它们呢?
  • 打印 key_pair_info.key_material
    AttributeError: 'ec2.KeyPairInfo' object has no attribute 'key_material'。这是因为key_material 在创建时只提供给用户一次。
  • 仅供参考,我主要与botocore(client)合作

    【问题讨论】:

      标签: python amazon-web-services amazon-ec2 boto3


      【解决方案1】:
      ec2 = boto3.resource('ec2')
      ec2.KeyPair('name')  # Get the key fingerprint AND the private key
      ec2.KeyPairInfo('name') # Get the key fingerprint ONLY
      
      
      ec2 = boto3.client('ec2')
      mykeypair = ec2.create_key_pair(KeyName='name') # Create a new keypair
      print mykeypair['KeyMaterial']
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-15
      • 2011-12-17
      • 2022-07-09
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 2019-07-25
      相关资源
      最近更新 更多