ERROR : An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair 'key-oregon.pem' does not exist

ERROR : An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair 'key-oregon.pem' does not exist

#!/bin/bash
# Get arguments
INSTANCE_TYPE='g4ad.xlarge'
MODEL_NAME='ResNet50'
PIXEL_SIZE= 224
BATCH_SIZE= 32
USING_GPU_NUM= 1
PROF_MODE = 'profiling'

IMAGE_ID="ami-0dda29f36c44fdbeb"
AWS_KEY="key-oregon.pem"
SUBNET_ID="subnet-90c369"
SG_ID="sg-c10060bee"

# Launch instance & get informations
echo 'launch instance'
LAUNCH_INFO=$(aws ec2 run-instances --image-id $IMAGE_ID --count 1 --instance-type $INSTANCE_TYPE \
--key-name $AWS_KEY --subnet-id $SUBNET_ID --security-group-ids $SG_ID)
sleep 60
echo 'get instance info'
INSTANCE_ID=$(echo $LAUNCH_INFO | jq -r '. | .Instances[0].InstanceId')
INSTANCE_DNS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '. | .Reservations[0].Instances[0].PublicDnsName')
echo $INSTANCE_DNS

执行上面的代码得到如下结果

错误1

An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair 'key-oregon.pem' does not exist get instance info

错误2

parse error: Invalid numeric literal at line 1, column 13

我把pem密钥放在了执行位置,为什么会出现这个错误?

$AWS_KEY 不是您的私人 pem 文件的名称。它是您在使用 create-key-pair 创建密钥时设置的 --key-name

另外你不应该在:

中有空格
PIXEL_SIZE= 224
BATCH_SIZE= 32
USING_GPU_NUM= 1
PROF_MODE = 'profiling'