我運行下面的腳本時,「密鑰對不存在」錯誤:AWS Boto3給予確切路徑
from __future__ import print_function
import paramiko
import boto3
#print('Loading function')
paramiko.util.log_to_file("/tmp/Dawny.log")
# List of EC2 variables
region = 'us-east-1'
image = 'ami-<>'
keyname = '<>.pem'
ec2 = boto3.resource('ec2')
instances = ec2.create_instances(ImageId=image, MinCount=1, MaxCount=1, InstanceType = 't2.micro', KeyName=keyname)
instance = instances[0]
instance.wait_until_running()
instance.load()
print(instance.public_dns_name)
def lambda_handler(event, context):
instances = ec2.create_instances(ImageId=image, MinCount=1, MaxCount=1, InstanceType = 't2.micro', KeyName=keyname)
instance = instances[0]
instance.wait_until_running()
instance.load()
print(instance.public_dns_name)
當我運行它,我得到這個錯誤:
botocore.exceptions.ClientError: An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair '<>.pem' does not exist
即使當我將完整路徑添加到密鑰對時,boto3給我提供了同樣的錯誤。 另外,我也試過這個:https://stackoverflow.com/a/34410564/4993513
還是,不起作用。
只是爲了進一步解釋...該命令不需要訪問您在磁盤上的密鑰對。相反,它將密鑰對的名稱發送給EC2,然後EC2將訪問已存儲在AWS上的已命名密鑰對,並在啓動實例時使用它。 –
@franklinsijo我擁有KeyPair。但是,我收到這個錯誤。另外,當我創建一個沒有KeyName屬性的實例時,它創建一個。但是,我無法在我的EC2儀表板中找到它:/。 [我也交叉檢查了訪問密鑰和祕密訪問密鑰] – Dawny33
傳遞沒有'.pem'擴展名的參數。 – franklinsijo