从Windows命令提示符启动Amazon EC2 t2.micro实例时出现错误

时间:2018-08-17 22:40:06

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

我是Amazon ec2服务的新用户。 我创建了一个Linux实例,并借助生成的ssh密钥,可以在Windows 7计算机上使用腻子将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

answer
复制粘贴命令使用双引号的方式存在错误。 我想要的是开始实例,而不是我在做aws ec2运行实例 以下命令启动了一个现有实例 C:\Users>aws ec2 start-instances --instance-ids i-03e7f6391a0f523ee

它启动了实例,但是要通过腻子连接到它,我必须查看IP地址,当实例状态从停止状态变为运行几天后,该IP地址已更改。

3 个答案:

答案 0 :(得分:0)

您的命令:

from functools import cmp_to_key
somelist.sort(key=cmp_to_key(f))

cmp=周围有“弯引号”,可能是由于从文字处理器(例如Microsoft Word)复制文本引起的。

用直引号替换它们:

key=

答案 1 :(得分:0)

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

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

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

您的AWS CLI版本很好。

答案 2 :(得分:0)

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

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