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

errors while launching amazon ec2 t2.micro instance from windows command prompt

我是 amazon ec2 服务的新用户。 我创建了一个 linux 实例,在生成的 ssh 密钥的帮助下,我能够在 Windows 7 机器上使用 putty ssh 进入实例。 我阅读了有关 link 部分下的文档 "launch and connect to instances"
https://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html
基于此,我 运行ning 在 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 运行-instances 以下命令启动了一个现有实例 C:\Users>aws ec2 start-instances --instance-ids i-03e7f6391a0f523ee

它启动了实例,但要通过 putty 连接到它,我必须查看 IP 地址,当实例状态从停止变为 运行ning 时,IP 地址在许多天后发生了变化。

您的命令:

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 左右有 'curly quotes',可能是由于从文字处理器(例如 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'

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

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

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

您的 AWS CLI 版本没问题。

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

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