在 boto python 的密钥对实例中放置什么参数?

What parameters to put in keypair instance in boto python?

我正在尝试创建一个 keyPair 实例,这就是我所拥有的。我应该在 create_key_pair 函数的参数中输入什么?我认为这将是关键,但它给了我一个错误,说我无权执行此操作。如有任何帮助,我们将不胜感激!

#establish connection to the region
conn = boto.ec2.connect_to_region('us-east-1', aws_access_key_id= aws_access_key_id, aws_secret_access_key = aws_secret_access_key )


#create the key pair
response = conn.create_key_pair(aws_secret_access_key, False)

您需要以下权限才能创建 EC2 密钥对:

ec2:DescribeKeyPairs (to select a key pair)
ec2:CreateKeyPair (to create a key pair)

创建密钥对 (boto3) 的示例:

    import boto3
    ec2 = boto3.client('ec2', region_name='us-east-1', aws_access_key_id='<access_key>',
aws_secret_access_key='<secret_key>')
    key = ec2.create_key_pair(KeyName='MY_KEY_PAIR_NAME')
    print(key)

或(boto):

    import boto.ec2
    conn = boto.ec2.connect_to_region('us-east-1',
                                      aws_access_key_id='<access_key>',
                                      aws_secret_access_key='<secret_key>')
    key = ec2.create_key_pair('MY_KEY_PAIR_NAME')
    print key