Skip to content

Commit c5e1c70

Browse files
Jaime Salas ZancadaJaime Salas Zancada
authored andcommitted
managng ips demo added
1 parent 67ba840 commit c5e1c70

7 files changed

Lines changed: 190 additions & 39 deletions

File tree

04-cloud/aws/06-configuring-security-groups/diagrams.drawio

Lines changed: 57 additions & 27 deletions
Large diffs are not rendered by default.
441 KB
Loading
173 KB
Loading
168 KB
Loading
Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,105 @@
1-
> TODO: Create EIP demo
1+
# Demo
2+
3+
We start from previously demo, where we have two instances running. The internal instance is only reachable from bastion instance. The problem that we face now is that our bastion instance is not associated with an elastic IP, so whenever we stop/run the instance the public IP will be revaluated and our connection setting throw away.
4+
5+
## Searching for instance
6+
7+
To assign an EIP, we need to know, the instance network interface unique identifier that we want to use. In our case the instance is the `bastion` one. So let's go ahead and try to solve this from AWS CLI. First let's grab all instance on london region:
8+
9+
```bash
10+
aws ec2 describe-instances --region eu-west-2
11+
```
12+
13+
We notice that we have a dedicated entry for network interface, inside the instance. The instance that we're interested on is just the `bastion` one so let's try to filter and grab only this one:
14+
15+
```bash
16+
aws ec2 describe-instances \
17+
--filters "Name=tag:Name,Values=bastion-server" \
18+
--region eu-west-2
19+
```
20+
21+
Now the response only comes with one instance. Now we need to get from overall response the network interface id:
22+
23+
```bash
24+
aws ec2 describe-instances \
25+
--filters "Name=tag:Name,Values=bastion-server" \
26+
--region eu-west-2 | jq -r '.Reservations[0].Instances[0].NetworkInterfaces[0]."NetworkInterfaceId"'
27+
```
28+
29+
We're going to need this value, so let's dump it into a variable:
30+
31+
```bash
32+
ENI=$(aws ec2 describe-instances \
33+
--filters "Name=tag:Name,Values=bastion-server" \
34+
--region eu-west-2 | jq -r '.Reservations[0].Instances[0].NetworkInterfaces[0]."NetworkInterfaceId"')
35+
```
36+
37+
```bash
38+
echo $ENI
39+
```
40+
41+
Now, allocate an Elastic IP address by running the `aws ec2 allocate-address` command. This will return an allocation ID.
42+
43+
```bash
44+
aws ec2 allocate-address --region eu-west-2
45+
```
46+
47+
We get a response similar to this one:
48+
49+
```json
50+
{
51+
"PublicIp": "18.168.219.50",
52+
"AllocationId": "eipalloc-08dfc2aab52a8e5a3",
53+
"PublicIpv4Pool": "amazon",
54+
"NetworkBorderGroup": "eu-west-2",
55+
"Domain": "vpc"
56+
}
57+
```
58+
59+
From this response, ee need the `AllocationId`, copy the value and dump it into terminal variable:
60+
61+
```bash
62+
ALLOCATIONID=eipalloc-08dfc2aab52a8e5a3
63+
```
64+
65+
Now, associate the allocated Elastic IP with a network interface or instance using the `aws ec2 associate-address` command.
66+
67+
> NOTE: We can use a network interface or instance, in this demo we're using the network interface.
68+
69+
```bash
70+
aws ec2 associate-address --allocation-id $ALLOCATIONID --network-interface-id $ENI --region eu-west-2
71+
```
72+
73+
We get something as follows:
74+
75+
```json
76+
{
77+
"AssociationId": "eipassoc-08b38f40473c7179f"
78+
}
79+
```
80+
81+
Move to EC2 dashboard on console and open `Elastic IPs`, we will find out our new EIP:
82+
83+
![new elastic ip](./.resources/eip/01.png)
84+
85+
Let's try to connect to our bastion server using this info
86+
87+
```bash
88+
ssh -i "london-key.pem" ec2-user@ec2-18-168-219-50.eu-west-2.compute.amazonaws.com
89+
```
90+
91+
Ok, now let's `exit` the instance, and from AWS console let's `stop` the bastion server:
92+
93+
> Image 2
94+
![stopping bastion](./.resources/eip/02.png)
95+
96+
Wait untill is full stopped. Notice that the `public IP` doesn't change, even when we have stopped the machine, ok, let's start it again:
97+
98+
> Image 3
99+
![starting bastion](./.resources/eip/03.png)
100+
101+
After is started, we can try previous SSH command and check that we can get into bastion server:
102+
103+
```bash
104+
ssh -i "london-key.pem" ec2-user@ec2-18-168-219-50.eu-west-2.compute.amazonaws.com
105+
```

04-cloud/aws/08-managing-ips/diagrams.drawio

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
1-
<mxfile host="app.diagrams.net" modified="2023-12-09T14:15:55.521Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" etag="n3RHYS2_PkrsCZegqLuJ" version="22.1.7" type="device">
1+
<mxfile host="app.diagrams.net" modified="2023-12-17T10:58:23.293Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" etag="dwxRtk53X5tc8e-AM6xi" version="22.1.11" type="device">
22
<diagram name="Page-1" id="O0BnVBZXtNPuLVPcpNwy">
3-
<mxGraphModel dx="1434" dy="820" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
3+
<mxGraphModel dx="1205" dy="630" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
44
<root>
55
<mxCell id="0" />
66
<mxCell id="1" parent="0" />
7-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-1" value="AWS Cloud" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud;strokeColor=#AAB7B8;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#AAB7B8;dashed=0;" vertex="1" parent="1">
7+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-1" value="AWS Cloud" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud;strokeColor=#AAB7B8;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#AAB7B8;dashed=0;" parent="1" vertex="1">
88
<mxGeometry x="40" y="80" width="760" height="490" as="geometry" />
99
</mxCell>
10-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-2" value="VPC 172.31.0.0/16" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_vpc;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" vertex="1" parent="1">
10+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-2" value="VPC 172.31.0.0/16" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_vpc;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" parent="1" vertex="1">
1111
<mxGeometry x="80" y="120" width="680" height="440" as="geometry" />
1212
</mxCell>
13-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-3" value="Internal Subnet 172.31.0.0/20" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_subnet;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" vertex="1" parent="1">
13+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-3" value="Internal Subnet 172.31.0.0/20" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_subnet;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" parent="1" vertex="1">
1414
<mxGeometry x="120" y="160" width="280" height="390" as="geometry" />
1515
</mxCell>
16-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-4" value="External Subnet 172.31.16.0/20" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_subnet;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" vertex="1" parent="1">
16+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-4" value="External Subnet 172.31.16.0/20" style="sketch=0;outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_subnet;strokeColor=#879196;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#879196;dashed=0;" parent="1" vertex="1">
1717
<mxGeometry x="439" y="161" width="280" height="390" as="geometry" />
1818
</mxCell>
19-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-5" value="" style="sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=#ED7100;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ec2;" vertex="1" parent="1">
19+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-5" value="" style="sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=#ED7100;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ec2;" parent="1" vertex="1">
2020
<mxGeometry x="210" y="240" width="78" height="78" as="geometry" />
2121
</mxCell>
22-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-6" value="" style="sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=#ED7100;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ec2;" vertex="1" parent="1">
22+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-6" value="" style="sketch=0;points=[[0,0,0],[0.25,0,0],[0.5,0,0],[0.75,0,0],[1,0,0],[0,1,0],[0.25,1,0],[0.5,1,0],[0.75,1,0],[1,1,0],[0,0.25,0],[0,0.5,0],[0,0.75,0],[1,0.25,0],[1,0.5,0],[1,0.75,0]];outlineConnect=0;fontColor=#232F3E;fillColor=#ED7100;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ec2;" parent="1" vertex="1">
2323
<mxGeometry x="540" y="240" width="78" height="78" as="geometry" />
2424
</mxCell>
25-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-7" value="172.31.30.92" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
25+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-7" value="172.31.30.92" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
2626
<mxGeometry x="203.5" y="325" width="91" height="30" as="geometry" />
2727
</mxCell>
28-
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-8" value="172.31.9.92&lt;br&gt;51.194.244.47" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
28+
<mxCell id="rYg6fZ0COP3Tx7WlOynZ-8" value="172.31.9.92&lt;br&gt;51.194.244.47" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
2929
<mxGeometry x="533.5" y="325" width="91" height="30" as="geometry" />
3030
</mxCell>
31+
<mxCell id="5XMmqp_fbMcfXs2NPOdR-1" value="" style="endArrow=classic;startArrow=classic;html=1;rounded=0;" edge="1" parent="1" target="rYg6fZ0COP3Tx7WlOynZ-6">
32+
<mxGeometry width="50" height="50" relative="1" as="geometry">
33+
<mxPoint x="288" y="280" as="sourcePoint" />
34+
<mxPoint x="338" y="230" as="targetPoint" />
35+
</mxGeometry>
36+
</mxCell>
37+
<mxCell id="5XMmqp_fbMcfXs2NPOdR-2" value="" style="endArrow=classic;startArrow=classic;html=1;rounded=0;" edge="1" parent="1" target="5XMmqp_fbMcfXs2NPOdR-3">
38+
<mxGeometry width="50" height="50" relative="1" as="geometry">
39+
<mxPoint x="618" y="280" as="sourcePoint" />
40+
<mxPoint x="820" y="280" as="targetPoint" />
41+
</mxGeometry>
42+
</mxCell>
43+
<mxCell id="5XMmqp_fbMcfXs2NPOdR-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.internet_2;fillColor=#D2D3D3;gradientColor=none;" vertex="1" parent="1">
44+
<mxGeometry x="870" y="252" width="79.5" height="54" as="geometry" />
45+
</mxCell>
3146
</root>
3247
</mxGraphModel>
3348
</diagram>

04-cloud/aws/08-managing-ips/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626
| Addressable from inside VPC only | Addressable from outside of VPC |
2727
| Stays the same for lifetime of instance | Allow and deny rules |
2828
| Based on subnet CIDR | Pulled from AWS pool of external IPs |
29-
| Assigned to all instances | Only assigned on launch if enabled |
29+
| Assigned to all instances | Only assigned on launch if enabled |
30+
31+
[Demo: Using EIP](./demos/02-eip.md)

0 commit comments

Comments
 (0)