SAA-C02 - EC2 Compute

Amazon Machine instances

Template of pre-configured EC2 instances so you can quickly launch one.
Lots of preset AMIs. Can have things pre installed e.g. tensorflow
Can create your own AMI: Take an AMI, launch, install custom apps, customise -> save as custom AMI.
Then can launch multiple. Good for autoscaling.

Instance types

choose the cpu numbers, cpu type, clock speed, memory, instance storage, network transfer trade, architecture, AVX (advanced vector extensions), turbo
Instance type families: organise these.

Instance purchasing options

  1. on demand instances:
  2. reserved instances (RI): discounted rate, set period of time, cheaper.
  3. scheduled instances:
  4. spot instances:
  5. on demand capacity reservation:

EC2 Tenancy

This is the underlying host the EC2 instance will reside on. Physical server.

EC2 Instance User data

Allows you to enter commands to run during boot cycle of the instance e.g. start up apache Can get the user data with

curl http://169.254.169.254/latest/user-data

EC2 Instance Metadata

This gets the instance metadata

curl http://169.254.169.254/latest/meta-data Can get e.g. ip address with curl http://169.254.169.254/latest/meta-data/ipaddress

Also access metadata by run

wget ec2-metadata Downloads a program which gives access to metadata

EC2 monitoring and status checks

EC2 monitoring Run every minute If all ok -> ok. Else -> impaired. System status checks -> aws need to troubleshoot. Instance status checks -> my responsibility.

Cloudwatch monitoring

Can configure alarms based on status checks (Cloudwatch), e.g. notification when cpu > 50%. Alarm can have actions. Cloudwatch be y default runs every 5 mins. Pay more for every minute.

Storage options

Security

need to set a security group: instance level firewall allows you to specify what traffic can come in and out.
Can set Source, port, protocol.
Need a key pair to encrypt and decrypt login information (.pem file). Need to download, can only download once.

Keys

Security setup

Download key pair and keep safe.
Can use same key par on multiple instances.
Once connected, can set up less privileged accounts with simpler logins.
Customer responsibility to install security patches. Default allows 0.0.0.0, open to all IP addresses.

Connecting

from WSL: ssh -i keys/cloud_academy_private_key.pem ec2-user@ip
from windows: putty, add ip address, SSH auth -> add key.

get EC2 metadata using curl from special ip address, e.g. curl -w "\n" http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key

Optimising costs

hard to buy RIs in correct size, constantly changing marketplace and requirements. Can't keep up to maximise savings.
Instance size doubles as you go to the next instance type level. Want to buy in smallest common denominator. Mix and match sizes.

3 years is tempting. There's an RI marketplace to sell back unused compute. Convertible or standard

savings plans

Cheaper than OnDemand, but commit to use a specific amount of compute power for 1 or 3 year term.

Savings Plans are a flexible pricing model that offer low prices on EC2, Fargate and Lambda usage, in exchange for a commitment to a consistent amount of usage (measured in $/hour) for a 1 or 3 year term.

Cannot sell savings plans

RI Marketplace Gold

approach

Elastic load balancer (ELB)

ELB summary

Manage and control flow of inbound requests and distribute to targets.
Targets can be multiple EC2, lambda, containers etc.
receives TCP traffic on port 80.

Single EC2 instance approach drawbacks are:

EBL is comprised of multiple instances managed by AWS, automatically scales.

Load Balancer types

ELB Components

SSL / TLS

Http is port 80, https is port 443
Https allows encrypted communication. Needs additional config for server certificate and security policy.
TLS is transport layer security. Same as HTTPS.
AWS Certificate manager (ACM): can create and provision certificates. Can use IAM to load 3rd party certificates. All are X509 standard.

Application load balancer

OSI: open services infrastructure Good for micro-servers and containers.

ALB setup

Go to listener to set up rules e.g. if source IP is a specific value, route to different target group

Network load balancer

Principals same as ALB, but this is for connections. Lower layer, TCP protocols. TCP, TLS, UDP.
Processes many requests per sec.
Cross zone can be disabled.

classic load balancer

less features, old

EC2 Auto scaling

EC2 auto scaling means add VMs when cpu > threshold, terminate EC2 instance when cpu < threshold (also other AWS services can auto scale)

EC2 auto scaling components

create template (or launch configuration, template is newer). Defines how auto scaling group builds new instances.
Basically the instructions to start a new instance.

creating launch templates:

Creating launch configuration:

Create auto scaling group:

Auto-scaling groups allow you to scale out (add more instances) or scale in (remove instances) based on metrics such as:

ELB and EC2 Autoscaling together

Generally need both together so whole thing goes up and down

Placement groups

Put instances in a placement group
Normally instances launches on different servers.
Might want to place close together for better node comms.
When launch, place EC2 in a placement group.
Rules so can't put e.g. micro in a cluster.
Spread and partition can be in multi AZs but cluster only in one AZ

IAM Roles

Can attach one role to an EC2 instance Instant effect Universal (any region)

Monitoring

Runs every minute, returns pass or fail. If one or more fail -> impaired Instance checks -> my responsibility
System status checks -> AWS
Cloudwatch can automatically perform actions on alarms

My Summary

Use ELB and Auto scaling together ELB responds flexibly to user requests, scaling up and down. Configure listeners, target groups, health checks. Set up launch template as model for the instances to be started (includes AMI, instance type, key pair, security group etc) Set up autoscaling to use this launch template, and to put the instances in the target group. Need a security group to say what traffic can access the instances.