-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting-ec2.txt
183 lines (171 loc) · 12.8 KB
/
listing-ec2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Script started on 2018-11-24 15:43:20+0100
# create a new security group to provide some isolation inside the cloud environment
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 create-security-group --group-name devenv-sg --description "security group for development environment"
-------------------------------------
| CreateSecurityGroup |
+----------+------------------------+
| GroupId | sg-0eba59e29f2a2c2c8 |
+----------+------------------------+
# created security-group and granted external access on SSH-port for the whole ipv4 space
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 authorize-security-group-ingress --group-name devenv-sg --protocol tcp --port 22 --cidr 0.0.0.0/0
# created a key pair to access the VM later (using passwordless SSH login)
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 create-key-pair --key-name devenv-key --query 'KeyMaterial' --output text > devenv-key.pem
# fix SSH key file permissions
mirko@tiger:~/Documents/MoCC exercise1$ chmod 400 devenv-key.pem
# run a new instance of an Amazon Linux Machine Image using the smallest available instance type
# the AMI ID is taken from the AWS Marketplace: Amazon Linux AMI (HVM / 64-bit)
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 run-instances --image-id ami-0f0debf49705e047c --security-group-ids sg-0eba59e29f2a2c2c8 --count 1 --instance-type t2.nano --key-name devenv-key --query 'Instances[0].InstanceId'
--------------
|RunInstances|
+------------+
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 describe-instances
---------------------------------------------------------------------------------------
| DescribeInstances |
+-------------------------------------------------------------------------------------+
|| Reservations ||
|+----------------------------------+------------------------------------------------+|
|| OwnerId | 145953835258 ||
|| ReservationId | r-06e613f9810544cd1 ||
|+----------------------------------+------------------------------------------------+|
||| Instances |||
||+------------------------+--------------------------------------------------------+||
||| AmiLaunchIndex | 0 |||
||| Architecture | x86_64 |||
||| ClientToken | |||
||| EbsOptimized | False |||
||| EnaSupport | True |||
||| Hypervisor | xen |||
||| ImageId | ami-0f0debf49705e047c |||
||| InstanceId | i-003b028bce5805df6 |||
||| InstanceType | t2.nano |||
||| KeyName | devenv-key |||
||| LaunchTime | 2018-11-24T15:28:26.000Z |||
||| PrivateDnsName | ip-172-31-35-170.eu-central-1.compute.internal |||
||| PrivateIpAddress | 172.31.35.170 |||
||| PublicDnsName | ec2-18-195-23-196.eu-central-1.compute.amazonaws.com |||
||| PublicIpAddress | 18.195.23.196 |||
||| RootDeviceName | /dev/xvda |||
||| RootDeviceType | ebs |||
||| SourceDestCheck | True |||
||| StateTransitionReason | |||
||| SubnetId | subnet-36a4f24b |||
||| VirtualizationType | hvm |||
||| VpcId | vpc-4e88b825 |||
||+------------------------+--------------------------------------------------------+||
|||| BlockDeviceMappings ||||
|||+----------------------------------------+--------------------------------------+|||
|||| DeviceName | /dev/xvda ||||
|||+----------------------------------------+--------------------------------------+|||
||||| Ebs |||||
||||+----------------------------------+------------------------------------------+||||
||||| AttachTime | 2018-11-24T15:28:26.000Z |||||
||||| DeleteOnTermination | True |||||
||||| Status | attached |||||
||||| VolumeId | vol-0244549145d725c79 |||||
||||+----------------------------------+------------------------------------------+||||
|||| Monitoring ||||
|||+---------------------------------+---------------------------------------------+|||
|||| State | disabled ||||
|||+---------------------------------+---------------------------------------------+|||
|||| NetworkInterfaces ||||
|||+-----------------------+-------------------------------------------------------+|||
|||| Description | ||||
|||| MacAddress | 06:6e:82:45:ed:ce ||||
|||| NetworkInterfaceId | eni-09962a7c9f4ec948b ||||
|||| OwnerId | 145953835258 ||||
|||| PrivateDnsName | ip-172-31-35-170.eu-central-1.compute.internal ||||
|||| PrivateIpAddress | 172.31.35.170 ||||
|||| SourceDestCheck | True ||||
|||| Status | in-use ||||
|||| SubnetId | subnet-36a4f24b ||||
|||| VpcId | vpc-4e88b825 ||||
|||+-----------------------+-------------------------------------------------------+|||
||||| Association |||||
||||+----------------+------------------------------------------------------------+||||
||||| IpOwnerId | amazon |||||
||||| PublicDnsName | ec2-18-195-23-196.eu-central-1.compute.amazonaws.com |||||
||||| PublicIp | 18.195.23.196 |||||
||||+----------------+------------------------------------------------------------+||||
||||| Attachment |||||
||||+-------------------------------+---------------------------------------------+||||
||||| AttachTime | 2018-11-24T15:28:26.000Z |||||
||||| AttachmentId | eni-attach-05abef6b470bf38ca |||||
||||| DeleteOnTermination | True |||||
||||| DeviceIndex | 0 |||||
||||| Status | attached |||||
||||+-------------------------------+---------------------------------------------+||||
||||| Groups |||||
||||+--------------------------+--------------------------------------------------+||||
||||| GroupId | sg-0eba59e29f2a2c2c8 |||||
||||| GroupName | devenv-sg |||||
||||+--------------------------+--------------------------------------------------+||||
||||| PrivateIpAddresses |||||
||||+---------------------+-------------------------------------------------------+||||
||||| Primary | True |||||
||||| PrivateDnsName | ip-172-31-35-170.eu-central-1.compute.internal |||||
||||| PrivateIpAddress | 172.31.35.170 |||||
||||+---------------------+-------------------------------------------------------+||||
|||||| Association ||||||
|||||+----------------+----------------------------------------------------------+|||||
|||||| IpOwnerId | amazon ||||||
|||||| PublicDnsName | ec2-18-195-23-196.eu-central-1.compute.amazonaws.com ||||||
|||||| PublicIp | 18.195.23.196 ||||||
|||||+----------------+----------------------------------------------------------+|||||
|||| Placement ||||
|||+------------------------------------------+------------------------------------+|||
|||| AvailabilityZone | eu-central-1b ||||
|||| GroupName | ||||
|||| Tenancy | default ||||
|||+------------------------------------------+------------------------------------+|||
|||| SecurityGroups ||||
|||+--------------------------+----------------------------------------------------+|||
|||| GroupId | sg-0eba59e29f2a2c2c8 ||||
|||| GroupName | devenv-sg ||||
|||+--------------------------+----------------------------------------------------+|||
|||| State ||||
|||+--------------------------------+----------------------------------------------+|||
|||| Code | 16 ||||
|||| Name | running ||||
|||+--------------------------------+----------------------------------------------+|||
# now really get the public IP address using this command (the IP is hidden when the output format is set to table)
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 describe-instances --instance-ids i-003b028bce5805df6 --query 'Reservations[0].Instances[0].PublicIpAddress' --output json
"18.195.23.196"
# connect to the virtual machine using standard SSH utils from the OS
mirko@tiger:~/Documents/MoCC exercise1$ ssh -i devenv-key.pem ec2-user@18.195.23.196
The authenticity of host '18.195.23.196 (18.195.23.196)' can't be established.
ECDSA key fingerprint is SHA256:8vzynBsHdXtr+gDElLk1zcEko0GmXWLB+XIjHITkWoQ.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '18.195.23.196' (ECDSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/
[ec2-user@ip-172-31-35-170 ~]$ groups
ec2-user wheel
[ec2-user@ip-172-31-35-170 ~]$ logout
Connection to 18.195.23.196 closed.
# shut down the test VM
mirko@tiger:~/Documents/MoCC exercise1$ aws ec2 terminate-instances --instance-ids i-003b028bce5805df6
-------------------------------
| TerminateInstances |
+-----------------------------+
|| TerminatingInstances ||
|+---------------------------+|
|| InstanceId ||
|+---------------------------+|
|| i-003b028bce5805df6 ||
|+---------------------------+|
||| CurrentState |||
||+-------+-----------------+||
||| Code | Name |||
||+-------+-----------------+||
||| 32 | shutting-down |||
||+-------+-----------------+||
||| PreviousState |||
||+---------+---------------+||
||| Code | Name |||
||+---------+---------------+||
||| 16 | running |||
||+---------+---------------+||
mirko@tiger:~/Documents/MoCC exercise1$ exit
Script done on 2018-11-24 16:47:19+0100