从Windows命令提示符启动amazon ec2 t2.micro实例时出错

问题描述 投票:0回答:2

我是amazon ec2服务的新用户。我创建了一个linux实例,在生成的ssh密钥的帮助下,我能够在Windows 7机器上使用putty ssh到实例中。我阅读了“启动并连接到实例”一节中的以下链接所提供的文档 https://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html 基于此我在Windows命令提示符下运行以下命令。

aws ec2 run-instances --image-id ami-d783a9b8 --subnet-id subnet-d3fdbabb --security-group-ids sg-0e81c2a33e1039f58 --count 1 --instance-type t2.micro --key-name “datastructutrekey” --query 'Instances[0].InstanceId' " i-03e7f6391a0f523ee"

但我收到了错误

An error occurred (InvalidParameterValue) when calling the RunInstances operatio
n: Invalid value 'A¢A?A?datastructutrekeyA¢A?A?' for keyPairNames. Text is not i
n valid ISO 8859-1 (Latin 1) encoding

D:\folder where aws keys are>" i-03e7f6391a
0f523ee"
'" i-03e7f6391a0f523ee"' is not recognized as an internal or external command,
operable program or batch file.

任何人都可以指出我在做什么错误,我该如何解决这个问题?

当我尝试按如下方式运行命令时

aws ec2 run-instances --image-id ami-d783a9b8 --subnet-id subnet-d3fdbabb --security-group-ids sg-0e81c2a33e1039f58 --count 1 --instance-type t2.micro --key-name “datastructutre key” --query ''Instances[0].InstanceId'' "i-03e7f6391a0f523ee"

我得到以下错误

Bad value for --query ''Instances[0].InstanceId'': Unexpected token: Instances:
Parse error at column 2, token "Instances" (UNQUOTED_IDENTIFIER), for expression
:
"''Instances[0].InstanceId''"
   ^

以上哪个命令更合适,如何修复上述错误?另外我发布了输出

aws ec2 describe-instances

这样它可以给你一个更好的主意

{
    "Reservations": [
        {
            "Groups": [],
            "Instances": [
                {
                    "AmiLaunchIndex": 0,
                    "ImageId": "ami-d783a9b8",
                    "InstanceId": "i-03e7f6391a0f523ee",
                    "InstanceType": "t2.micro",
                    "KeyName": "datastructutre key",
                    "LaunchTime": "2018-08-01T04:28:52.000Z",
                    "Monitoring": {
                        "State": "disabled"
                    },
                    "Placement": {
                        "AvailabilityZone": "ap-south-1a",
                        "GroupName": "",
                        "Tenancy": "default"
                    },
                    "PrivateDnsName": "ip-172-31-20-16.ap-south-1.compute.internal",
                    "PrivateIpAddress": "172.31.20.16",
                    "ProductCodes": [],
                    "PublicDnsName": "",
                    "State": {
                        "Code": 80,
                        "Name": "stopped"
                    },
                    "StateTransitionReason": "",
                    "SubnetId": "subnet-d3fdbabb",
                    "VpcId": "vpc-08356c60",
                    "Architecture": "x86_64",
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "AttachTime": "2018-08-01T04:28:52.000Z",
                                "DeleteOnTermination": true,
                                "Status": "attached",
                                "VolumeId": "vol-09716d3308f44c63f"
                            }
                        }
                    ],
                    "ClientToken": "",
                    "EbsOptimized": false,
                    "EnaSupport": true,
                    "Hypervisor": "xen",
                    "NetworkInterfaces": [
                        {
                            "Attachment": {
                                "AttachTime": "2018-08-01T04:28:52.000Z",
                                "AttachmentId": "eni-attach-08d060230b617ca70",
                                "DeleteOnTermination": true,
                                "DeviceIndex": 0,
                                "Status": "attached"
                            },
                            "Description": "",
                            "Groups": [
                                {
                                    "GroupName": "launch-wizard-1",
                                    "GroupId": "sg-0e81c2a33e1039f58"
                                }
                            ],
                            "Ipv6Addresses": [],
                            "MacAddress": "02:5a:17:52:69:a6",
                            "NetworkInterfaceId": "eni-0146aab6d9503bf47",
                            "OwnerId": "1****************",
                            "PrivateDnsName": "ip-172-31-20-16.ap-south-1.compute.internal",
                            "PrivateIpAddress": "172.31.20.16",
                            "PrivateIpAddresses": [
                                {
                                    "Primary": true,
                                    "PrivateDnsName": "ip-172-31-20-16.ap-south-1.compute.internal",
                                    "PrivateIpAddress": "172.31.20.16"
                                }
                            ],
                            "SourceDestCheck": true,
                            "Status": "in-use",
                            "SubnetId": "subnet-d3fdbabb",
                            "VpcId": "vpc-08356c60"
                        }
                    ],
                    "RootDeviceName": "/dev/xvda",
                    "RootDeviceType": "ebs",
                    "SecurityGroups": [
                        {
                            "GroupName": "launch-wizard-1",
                            "GroupId": "sg-0e81c2a33e1039f58"
                        }
                    ],
                    "SourceDestCheck": true,
                    "StateReason": {
                        "Code": "Client.InstanceInitiatedShutdown",
                        "Message": "Client.InstanceInitiatedShutdown: Instance initiated shutdown"
                    },
                    "VirtualizationType": "hvm",
                    "CpuOptions": {
                        "CoreCount": 1,
                        "ThreadsPerCore": 1
                    }
                }
            ],
            "OwnerId": "1xxxxxxxx",
            "ReservationId": "r-xxxxxxxxxx"
        }
    ]
}

还有C:\ Users> aws --version

aws-cli/1.15.80 Python/3.7.0 Windows/7 botocore/1.10.79

回答 双重引号通过复制粘贴命令出现错误。我想要的是start-instance而不是我在执行aws ec2 run-instances命令后启动了现有实例C:\Users>aws ec2 start-instances --instance-ids i-03e7f6391a0f523ee

它启动了实例但是通过putty连接到它我不得不查看IP地址,当实例状态在停止多天后从停止状态变为运行状态时,IP地址被更改。

amazon-web-services amazon-ec2 cloud ec2-ami
2个回答
0
投票

我不确定您使用的是哪种键盘或语言设置...

对于您的第一个命令,您输入了一些不是标准引号的奇怪引号。编辑命令并将其替换为普通命令。接下来,该命令在结尾处指定实例id“i-03e7f6391a0f523ee”。删除它。对于您的问题,您将以不同方式指定密钥对名称。弄清楚正确的名称并使用它。

对于第二个命令,您再次使用奇怪的语法来引号。在这里,您使用两个单引号而不是一个引号。您最后还有该实例ID。删除它。

您的AWS CLI版本没问题。


0
投票

你的命令:

aws ec2 run-instances --image-id ami-d783a9b8 --subnet-id subnet-d3fdbabb --security-group-ids sg-0e81c2a33e1039f58 --count 1 --instance-type t2.micro --key-name “datastructutrekey” --query 'Instances[0].InstanceId'

datastructutrekey周围有'曲线引号',可能是由于从文字处理器复制文本(例如Microsoft Word)引起的。

用直引号替换它们:

aws ec2 run-instances --image-id ami-d783a9b8 --subnet-id subnet-d3fdbabb --security-group-ids sg-0e81c2a33e1039f58 --count 1 --instance-type t2.micro --key-name "datastructutrekey" --query 'Instances[0].InstanceId'
© www.soinside.com 2019 - 2024. All rights reserved.