This is an old revision of the document!
AWS CLI:
https://blog.ipspace.net/2021/02/vpc-subnets-aws-azure-gcp.html
Note we will use the cli account for Terraform as well (more below).
aws configure --profile jaimecli
./refresh_mfa.py jaimecli # to refresh the token with my mfa (it'll be a new entry in ~/.aws/config)
aws --profile jaimecli sts get-caller-identity # to test all is good. Do not forget the profile
Refreshing workaround for error “…The security token included in the request is expired”: disruptive
mv .aws/credentials credentials.bak2
aws configure
./refresh_aws_mfa.py jaimecli
SIMPLER SETUP. remove credentials when done and set them up again when start working:
# or just keep credentials but gran/revoke policies during works : https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1#/groups/details/gr2?section=permissions
rm /home/pi/.aws/credentials*
aws configure
aws sts get-caller-identity
! when logging off
rm /home/pi/.aws/credentials*
aws ec2 describe-vpcs | jq .[]
aws ec2 describe-subnets
aws ec2 describe-internet-gateways
aws ec2 describe-network-acls --query NetworkAcls[1] # this is just to output the 2nd acl
aws ec2 describe-instances --region us-east-1 | jq -r .Reservations[].Instances[].PublicIpAddress # lists all addresses: public and elastic
aws ec2 describe-regions --output text
aws ec2 describe-regions | jq -r "[[.Regions[].Endpoint[]]" # to parse json output
Find all instances in all regions:
for region in `aws ec2 describe-regions --profile jaime-personal --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --profile jaime-personal --region $region
done
Find all IPs (elastic and public) for instances in all regions. Or this other WAY: External Link
for region in `aws ec2 describe-regions --output text | cut -f3`
do
aws ec2 describe-instances --region $region | jq -r .Reservations[].Instances[].PublicIpAddress
done
Find all IPs (elastic and public) for LB in all regions:
# ALB LOAD BALANCERS
for region in `aws ec2 describe-regions --output text | cut -f3`
do
aws elbv2 describe-load-balancers --region $region | jq -r .LoadBalancers[].DNSName
done
# ELB LOAD BALANCERS
for region in `aws ec2 describe-regions --output text | cut -f3`
do
aws elb describe-load-balancers --region $region | jq -r .LoadBalancerDescriptions[].DNSName
done
AWS TERRAFORM
Install Terraform ; Vault
Import existing infrastructure to start playing with
-
AS14618 ; ASN15509
For a full current amazon IPs, see THIS
VPC: Analogy with a distribution layer (one for qa, one for prod, one for eat…) A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. Components
External Link & some definitions (from
https://aws.amazon.com/vpc/faqs )
Public IP (ephemeral , with public=true in the api call): They change when the instance reboots.
ELASTIC IP ~= PUBLIC-PERMANENT: Is a reserved public IP associated with the User Account. It exists until it is explicitly removed, and remains associated with the account even while it is associated with no instance. Is not free.
Elastic network interfaces (ENI): Can moved between ec2 and takes the mac address with it.
VPC Endpoints [vpce] : 'gateways' to aws services (mainly S3 and DynamoDB). Access to AWS services is done normally via public IPs (not really going out to internet). With vpc endpoint, we can do it via internal IPs. See
External_Link
SUBNETS: Public private or hybrid (egress only) subnet is an category we give, depending on how traffic is routed. Is not an AWS concept.
SECURITY GROUP: Defined on an Instance Basis they work up to layer 4. Ideally used to east to west traffic and sometimes for north-south (but we can use 3rd party instances like fw. We can define one by one but not really scalable. Better approach is to define it for multiple instances, Virtual firewall that controls the traffic for one or more instances. VPC router enables Amazon EC2 instances within subnets to communicate with Amazon EC2 instances in other subnets within the same VPC.
ACL [acl]: Stateless and defined on a VPC level
NAT GATEWAY [ngw] : Associated to a subnet. NAT is used to allow traffic outbound and prevent traffic inbound.
INTERNET GATEWAY [igw]:
ROUTE TABLES [rtb]: they have 'destination' (the subnet for what we want the route) and 'target' (which can be equated to the 'gateway'
A rtb lives in a subnet or subnets (associated)
An example, rtb for a vpc endpoint: destination: pl-7ba54012(com.amazonaws.us-est-2.s3) (this represents the subnet of the service) + target: vpce-aa852c
There's really one route table attached to each interface and all goes through gre tunnels. Nonetheless, logically there are multiple rts.
All rts are egress except the IG.
Ingress table only happens on the IG. It is specially named rt called 'gateway-rt'
From the IG to the VPC (in case dst is not the vm, ie: firewall in the dmz or similar):
Another use case for the gateway-rt is the network-firewall:
The trick here is for the traffic coming from internet, the gateway-rt routes traffic destined to the vpc prefix to the firewall nic instead (see picture)
Egress Only IG (eigw) is needed for IPv6 because they get the public ipv6 straight in the ec2 interfaces, therefore there is not natgw. eigw is the only way to have an outbound only internet connection.
TRANSIT GATEWAY [tgw] : Similar to transit vpc but more 'router-like'. For hub and spokes type deployments.
VPCs, on-premise stuff and so on, all can connect to the tgw : In the transit gatewaym, we create VPC attachments, then in the VPC we can leave the deafult table (automatically created) or add custom routes with target [tgw]
If we want traffic between different regions we can do it but peering together transit gateways.
-
You can create attachments from the tgw to subnets
VPC PEERING pcx: A peering connection enables you to route traffic via private IP addresses between two peered VPCs.
PRIVATE LINK: Differently from vpc peering because allows you to publish an “endpoint” that others can connect with from their own VPC. A bit like service provider flavour.
Unidirectional, natted and optimized (ie supports more spoke VPCs)
Interface VPC Endpoints: vpce-svc An interface VPC endpoint (interface endpoint) enables you to connect to services powered by AWS PrivateLink
It can work inter-region on top of vpc peering. See
Link
Transit vpc is a bit of a
hack. not really an aws contruct but a solution we can build ourselves with a vpc.
LINK
AWS service endpoints: To connect programmatically to an AWS service
DIRECTCONNECT [dgw] External Link
VIF
DirectConnect Gateway: We can think of it as a ROUTE REFLECTOR. Not in the forwarding plane.
External Link. It then connects to one the these two:
Directconnect can be used with multiple regions single [dgw] connects to multiple [vpg] in different regions.
Directconnect can be used with multiple accounts: [dgw] belongs to account Z, then accounts A and B send 'association requests' from their [vpg]]
Depending on what we want to access we can create the following interfaces (VIFs) in DirectConnect:
BGP MP is not supported. MD5 is enabled by default.
LoadBalancers ELB( ALB/NLB):
See External Link
ELB: Used to be called Classic (was the first)
ALB (Application): They use target groups (more like netscaler). The ALB comes with a lot of built-in features. See the comparison table at the end of the article.
NLB (Application): They use target groups (more like netscaler). The NLB comes with a few rough edges and requires more experience and care.
The lb gets a url per region of the type elb.amazonaws.com. That url (without route 53) has multiple A records corresponding to the multiple listeners.
ELB: Inbound. One ELB per vip, so we will likely run several of them.
ALB (Application): above plus augmented feats.
ALB is an instance but under Aws control.sni. Aka reverse proxy: one connection to the alb, then it creates another to the backend and Then a third one from the customer to the backend! 1←- ,2 ←- ←– , 3 ←—-
)
TO FIND THE SECURITY GROUP SG FROM AN IP (normally that IP is from an ELB but this works the same for instances):
section-EC2: go to network interfaces and search for that IP. You will get an eni interface, copy the description (an elb description, trim the elb bit)
section-EC2 go to load balancers and paste the descriptio. You will see the lb containing that IP.
scroll down and the SG is there
DNS:
Options:
ROUTE 53
AWS GATEWAY LOAD BALANCER (ipspace)
GWLB is used for NVAs (network virtual appliances) that can be provided by 3rd parties.
Geneve tunnels between gwlb and the nvas
Review traffic flow ig has ingress table!
AWS FIREWALL (ipspace)
Ingress tablet Only happens on the IG (that's why we need IG to redirect to the firewall rt (and when using natgw we have peculiar placement of natgw see ipspace:
Flow:
~ Managed gateway load balancer. Bump in the wire.
Two subnets needed App-RT and FW-RT for the filtered traffic towards internet (0/0)
For IG/NAT-GW. Tweaks for inter VPC firewall. Cannot filter intra-vpc traffic.
Suricata open source firewall. Layer 4.
IGW - FW - NGW - SRV
The FW needs to be attached to each of the AZs
FIREWALL POLICY (just a set of policies). Stateless and stateful rules.
LAN TO AWS VPN TUNNEL:
Meraki to AWS VPN
Always two tunnels to the vgw. If need very high speec (up to 25G), use a EC2-based-vpn (vendor specific).
Cisco Intercloud extender: from private cloud (OVA) format to AWS (AMI format)
CFT (Cloud Formation Templates)
Allow to create a whole environment on demand. Consider that we pay for what we use in aws, therefore whatever infrastructure not in used shouldn't be deployed empty.
There are just txt templates that can be invoked via API (by the own dev team and/or the application)·
AWS LIMITS:
More info here
MONITORING:
Cloud watch
VPC mirroring:
Is rspan with VXLAN udp-4789 as transport. Target doesn't need to filter vxlan but we need to consider the 60B added by vxlan so we don't get over the mtu.
In reality the nitro nic (hypervisor's smart nic) does acl does sg does rspan and cloudwatch metrics(review this))
Aws global accelerator:
for those applications that cannot spell dns.
Traffic hits an Anycast address and then goes through Aws internal network.
Aws internal network uses public space.
Your endpoint needs to have public IP, eg alb or nlb
For my tests:
Instance types: Instance Type (tX X is the number, edition):
Price: T3a instances offer an additional 10% cost savings over T3 instances. T3 instances are 10% cheaper than the older T2 instances and offer up to a 30% better price to performance ratio.
amzn2-ami-hvm-2.0.20190823.1-x86_64-gp2 - ami-0b69ea66ff7391e80
t3a.nano
NAT gateway is pricy. For outbound internet access, is much cheper to use a gateway endpoint just for being on. ~60$ month
EC2 instances in 'stopped' state they do generate charges!
To control charges:
CloudWatch billing alerts and alarms, budgets, and CloudTrail. For more information on these services and their features, please review the documentation links below:
-
-
-
STORAGE:
Block Storage (EBS)
File storage (EFS)
Object storage (S3)
SECURITY FOR PROGRAMATIC ACCESS:
aws_security.pdf slides by from Michael J. Shannon (oreilly presentation aws security crash course)_
Have a look at aws secret manager
IAM manage policies
they are basically json files.
Policies attach to » >GROUP< gets users « attached
Three main kind of categories for policies: Administrator
role: is like an 'impersonation', like a mask!. IAM entity permissions can be Assumed by another entity
REGIONS AND AVAILABILITY ZONES
AWS EDGE LOCATIONS
CloudFront, Route 53, WAF
Entry points for aws cloud. Not strictly in the aws cloud.
Between the edge location and the outside world, there's a local caching data center.
AUTOESCALE CLOUD INFRASTRUCTURE:
AWS autoescaling features only deal with EKS (workers) or EC2 instances. If we want to dynamically allocate other resources like, subnets, directconnects, vpc peerings ans so on, we can use:
Amazon VPC Flow Logs - TODO