@@ -8,6 +8,9 @@ import { hashElement } from "folder-hash";
8
8
import { size } from "./size" ;
9
9
10
10
export = async ( ) => {
11
+ // Get a key pair to connect to the EC2 instance. If the name of an existing key pair is
12
+ // provided, use it, otherwise create one. We get the private key from config, or default to
13
+ // the default id_rsa SSH key.
11
14
const config = new pulumi . Config ( ) ;
12
15
const keyName = config . get ( "keyName" ) ??
13
16
new aws . ec2 . KeyPair ( "key" , { publicKey : config . require ( "publicKey" ) } ) . keyName ;
@@ -16,14 +19,15 @@ export = async () => {
16
19
Buffer . from ( privateKeyBase64 , 'base64' ) . toString ( 'ascii' ) :
17
20
fs . readFileSync ( path . join ( os . homedir ( ) , ".ssh" , "id_rsa" ) ) . toString ( "utf8" ) ;
18
21
22
+ // Create a security group that allows SSH traffic.
19
23
const secgrp = new aws . ec2 . SecurityGroup ( "secgrp" , {
20
24
description : "Foo" ,
21
25
ingress : [
22
26
{ protocol : "tcp" , fromPort : 22 , toPort : 22 , cidrBlocks : [ "0.0.0.0/0" ] } ,
23
- { protocol : "tcp" , fromPort : 80 , toPort : 80 , cidrBlocks : [ "0.0.0.0/0" ] } ,
24
27
] ,
25
28
} ) ;
26
29
30
+ // Get the latest Amazon Linux AMI (image) for the region we're using.
27
31
const ami = aws . ec2 . getAmiOutput ( {
28
32
owners : [ "amazon" ] ,
29
33
mostRecent : true ,
@@ -33,6 +37,7 @@ export = async () => {
33
37
} ] ,
34
38
} ) ;
35
39
40
+ // Create the EC2 instance we will copy files to.
36
41
const server = new aws . ec2 . Instance ( "server" , {
37
42
instanceType : size ,
38
43
ami : ami . id ,
@@ -42,18 +47,14 @@ export = async () => {
42
47
replaceOnChanges : [ "instanceType" ] ,
43
48
} ) ;
44
49
50
+ // The configuration of our SSH connection to the instance.
45
51
const connection : types . input . remote . ConnectionArgs = {
46
52
host : server . publicIp ,
47
53
user : "ec2-user" ,
48
54
privateKey : privateKey ,
49
55
} ;
50
56
51
- const connectionNoDialRetry : types . input . remote . ConnectionArgs = {
52
- ...connection ,
53
- dialErrorLimit : 1 ,
54
- } ;
55
-
56
- // We poll the server until it responds.
57
+ // Poll the server until it responds.
57
58
//
58
59
// Because other commands depend on this command, other commands are guaranteed
59
60
// to hit an already booted server.
0 commit comments