#!/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
Execute the above code and get the following result.
error1
An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair 'key-oregon.pem' does not exist get instance info
error2
parse error: Invalid numeric literal at line 1, column 13
I put the pem key in the execution location, why am I getting this error?
CodePudding user response:
The $AWS_KEY is not the name of your private pem file. It is the --key-name which you set when you created the key using create-key-pair.
Also you shouldn't have spaces in:
PIXEL_SIZE= 224
BATCH_SIZE= 32
USING_GPU_NUM= 1
PROF_MODE = 'profiling'
