【问题标题】:errors while launching amazon ec2 t2.micro instance from windows command prompt从 Windows 命令提示符启动 amazon ec2 t2.micro 实例时出错
【发布时间】:2023-03-19 00:54:01
【问题描述】:

我是亚马逊 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 地址。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 cloud ec2-ami


    【解决方案1】:

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

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

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

    您的 AWS CLI 版本没问题。

    【讨论】:

    • 如何找出密钥对名称我用 datastructurekey.pem 文件下载了密钥对,据我记得在网络上创建时的名称有一个空格数据结构密钥,我使用双引号是因为名称中的空格。这不是正确的事情吗,因为在 linux 中,我们通常可以使用反斜杠来省略 windows 中文件名中的空格,我不知道。这是具有 EN-US 默认语言的普通 QWERTY 键盘。
    • 笔记本电脑型号为 Dell Inspiron 1545。
    • 您的密钥对的文件名不是密钥对名称。转到 AWS 控制台 -> EC2 -> 密钥对并查找名称。或使用 CLI“aws ec2 describe-key-pairs”。您可以在包含空格的名称周围使用双引号(而不是两个单引号)。对于 Windows 和 Linux 也是如此。我认为您将转义引号与使用引号混淆了。请记住,不要从文章中复制和粘贴命令。有些使用非 ASCII 字符集。
    • 运行实例“创建”一个新实例。 start-instance “启动”一个现有实例。 docs.aws.amazon.com/cli/latest/reference/ec2/…
    【解决方案2】:

    你的命令:

    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'
    

    【讨论】:

    • 你指对了我是从 microsoft word 文件中复制粘贴命令我复制粘贴了你上面提到的行。然后我收到以下错误C:\Users\>aws ec2 run-instances --image-id ami-d783a9b8 --subnet-id subnet-d 3fdbabb --security-group-ids sg-0e81c2a33e1039f58 --count 1 --instance-type t2.m icro --key-name "datastructutrekey" --query 'Instances[0].InstanceId' An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operat ion: The key pair 'datastructutrekey' does not exist
    • 那是因为密钥对不存在。在 EC2 管理控制台中,单击左侧导航窗格中的 Key Pairs。使用列表中显示的密钥对的名称。我认为您在datastructutrekey 中有错字
    • 是的,你猜对了,有一个打字错误,我已经用答案更新了问题
    【解决方案3】:

    如何使用 PuTTy 从您的笔记本电脑连接到 AWS Linux 实例

    1. 启动 EC2 实例
    2. 我选择了 Red Hat Linux AMI 来安装 Linux 映像。
    3. 已创建新的密钥对 .pem 文件。
    4. 在我的笔记本电脑上安装 Putty。
    5. 运行 PuTTyGen 并单击加载
    6. 更改为选择所有文件 (.)。
    7. 然后选择 .pem 文件
    8. 然后点击保存私钥
    9. 并为这个新密钥对命名。
    10. 现在您可以使用 putty 连接您的实例
    11. 复制并粘贴您的 linux 实例的公共 ip
    12. 接下来展开 SSH 并点击 Auth。
    13. 点击浏览并从保存位置选择新的密钥对,点击打开
    14. 如果您想保存此内容,请转到左侧类别的顶部,然后单击会话
    15. 在已保存会话下键入名称,然后单击保存。
    16. 现在您可以打开会话,提供 ec2-user 并按 Enter 您现在已连接。

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2020-08-08
      • 2015-09-13
      • 2018-01-08
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多