[英]how to launch ec2 instance using AWS SDK and connect to it via AWS CLI
this is a newbie question. 这是一个新手问题。 Please, bear with me.
请多多包涵。
I tried to create an instance using AWS SDK for JAVA by following the official tutorial. 我尝试按照官方教程使用适用于JAVA的AWS开发工具包创建实例。 When It comes to the key pair part I get confused :
当谈到密钥对部分时,我会感到困惑:
CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();
createKeyPairRequest.withKeyName("azzouz_key");
CreateKeyPairResult createKeyPairResult = Client.createKeyPair(createKeyPairRequest);
KeyPair keyPair = new KeyPair();
keyPair = createKeyPairResult.getKeyPair();
String privateKey = keyPair.getKeyMaterial();
RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
runInstancesRequest.withImageId("ami-4b814f22")
.withInstanceType("m1.small")
.withMinCount(1)
.withMaxCount(1)
.withKeyName("azzouz_key")
.withSecurityGroups("Azzouz_group");
By doing like this, how can I use aws cli to connect to the instance I created using the SDK, I mean how to locate the .pem file ( if it does exist ). 这样,如何使用aws cli连接到使用SDK创建的实例,就意味着如何找到.pem文件(如果存在)。 Is my logic correct in term of creating ec2 instance using the code and manage it via aws cli, or it should all be in the same way?!
就使用代码创建ec2实例并通过aws cli进行管理而言,我的逻辑是正确的,还是应该以相同的方式进行?
The PEM key is in the contents of your privateKey
String variable. PEM密钥位于
privateKey
String变量的内容中。 You need to write that out to a file, as this is the only time you will be able to get to it via the API. 您需要将其写到文件中,因为这是您唯一一次可以通过API进行访问的文件。
To connect to the server, you don't use the AWS CLI. 要连接到服务器,请不要使用AWS CLI。 You would use the
ssh
command. 您将使用
ssh
命令。 I would read the answers to this question for more information about using SSH to connect to an EC2 server: how to login to ec2 machine? 我将阅读此问题的答案,以获取有关使用SSH连接到EC2服务器的更多信息: 如何登录ec2机器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.