> For the complete documentation index, see [llms.txt](https://awsfdn.adot8.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://awsfdn.adot8.com/module-6.md).

# Module 6

### AWS Compute Services

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2Fq4G3ZxIaIHgkMgB6oRxW%2Fimage.png?alt=media&amp;token=d5984d82-b5d5-4550-9498-94e642daf261" alt=""><figcaption></figcaption></figure>

### Categorizing compute services

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2F3zchp7NYer0Dp7W4rCqz%2Fimage.png?alt=media&amp;token=1d7c514d-e842-4174-afbf-f37ff8320a8e" alt=""><figcaption></figcaption></figure>

### Choosing the optimal compute service

Choosing the most optimal compute service really just depends on what you will be using it for

Some aspects to consider:

* What is your application design?
* What are your usage patterns?
* Which configuration settings will you want to manage?

{% hint style="info" %}
Selecting the wrong compute solution for an architecture can lead to lower performance efficiency
{% endhint %}

### Amazon Elastic Compute Cloud (Amazon EC2)

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FnFLyWTLhYHhf0TnVFnfc%2Fimage.png?alt=media&amp;token=cdf84757-58ef-4a4d-a812-3c997a4293c0" alt=""><figcaption></figcaption></figure>

Amazon EC2 can almost host anything

Examples:

* Application servers
* Web servers
* Database servers
* Game servers
* Mail servers
* Media servers
* Catalog servers
* File servers
* Computing servers
* Proxy servers

### Launching an Amazon EC2 instance

1. Select an AMI (Amazon Machine Image)

An AMI is a template that is used to create an EC2 instance, Windows or Linux and often also has some software-installed

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FWQlb5zRf5zYAPIVfGJfW%2Fimage.png?alt=media&amp;token=1edfe3fb-93a5-4864-9ce2-7a73ad518893" alt=""><figcaption></figcaption></figure>

2. Select an instance type

Instance types comprise varying combinations of CPU, memory, storage, and networking capacity.

Instance type categories:

* General purpose
* Compute optimized
* Memory optimized
* Storage optimized
* Accelerated computing

{% hint style="info" %}
Network bandwidth can also be configured (up to 100 gbps)
{% endhint %}

#### EC2 instance type naming and sizes

Example: t3.large

* T is the family
* 3 is the generation&#x20;
* Large is the size

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FHkEWeusdvI3wkWatDW5T%2Fimage.png?alt=media&amp;token=f7a0e9d1-1241-4a6e-8e51-53db576091df" alt=""><figcaption></figcaption></figure>

3. Specify network settings

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FxVyGDI33M0CjifQNLrUT%2Fimage.png?alt=media&amp;token=6e5f20f4-d8f1-4b75-bc85-044b9ad3c764" alt=""><figcaption></figcaption></figure>

4. Attach IAM role (optional)

Will software on the EC2 instance need to interact with other AWS services? If yes, attach an appropriate IAM Role.

An AWS Identity and Access Management (IAM) role that is attached to an EC2 instance is kept in an instance profile

{% hint style="info" %}
You can also attach a role to an instance that already exists
{% endhint %}

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FZy6XsVryHwocWQgsFEN2%2Fimage.png?alt=media&amp;token=f9abb542-844e-4e5f-b5a7-6e1f10bdad6b" alt=""><figcaption></figcaption></figure>

5. User data script (optional)

You can place a script that will automatically install a webserver or specific packages on instance launch for example.

{% hint style="success" %}
"A script that is going to be executed when an instance is created"
{% endhint %}

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FZcEZWVPk8XhFlrIlQGut%2Fimage.png?alt=media&amp;token=d5228c82-7833-48ea-844e-8a8fa7ff4c0c" alt=""><figcaption></figcaption></figure>

6. Specify Storage

Configure the root volume where the guest os will be installed. You can also attach additional storage volumes.

Each volume must have the following specified:

* The size of the disk (in GB)
* The volume type
* Different types of solid-state drives (SSDs) and hard disk drives (HDDs) are available
* If the volume will be deleted when the instance is terminated
* If encryption should be used

#### Amazon EC2 storage options

* Amazon Elastic Block Store (Amazon EBS)&#x20;
  * Durable, block-level storage volumes.
  * You can stop the instance and start it again, and the data will still be there
* Amazon EC2 Instance Store&#x20;
  * Ephemeral storage is provided on disks that are attached to the host computer where the EC2 instance is running.
  * If the instance stops, the data stored here is deleted
* Other (not for root volume)
  * Mount an Amazon Elastic File System (Amazon EFS) file system.
  * Connect to Amazon Simple Storage Service (Amazon S3)

{% hint style="info" %}
You can increase the size of an EBS but you can't decrease it
{% endhint %}

#### Example storage options

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FfsK70HRYyUuJJte0vOor%2Fimage.png?alt=media&amp;token=486b353f-f3b7-4ad2-98e2-3b38fcaa5ce6" alt=""><figcaption></figcaption></figure>

7. Add tags

Tags are labels that are used to groups elements and filter elements. They are key value pairs

8. Security Group Settings

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FmjL6ZGytHmigedmKSSyv%2Fimage.png?alt=media&amp;token=c2bf10ac-7c54-4216-a57f-b7a0c2ed3eb0" alt=""><figcaption></figcaption></figure>

9. Identify or create a key pair (just generating an ssh key pair)

#### Amazon CLI instance creation

```
aws ec2 run-instances \--image-id ami-1a2b3c4d \--count 1 \--instance-type c3.large \--key-name MyKeyPair \--security-groups MySecurityGroup \--region us-east-1
```

### Amazon EC2 instance lifecycle

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FKWeCBJstzNQOFZs4e3zD%2Fimage.png?alt=media&amp;token=581c1848-9a5b-48a7-8c97-f5577841ba41" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Rebooting an instance will not change any IP addresses or DNS hostnames **BUT** when an instance is stopped and then started again the public IP and hostname will change
{% endhint %}

{% hint style="success" %}
You can use an Elastic IP address with an instance to have a persistent public IP address
{% endhint %}

EC2 instance metadata and user-data can be seen with the following URL

```
http://169.254.169.254/latest/meta-data/
http://169.254.169.254/latest/user-data/
```

### Amazon CloudWatch for monitoring

Amazon CloudWatch is used to monitor EC2 instances. It provides near-real-time metrics, maintains 15 months of historical data, and a cool dashboard full of charts :D&#x20;

* Basic monitoring is the default, comes with no costs and updates every 5 minutes
* Detailed monitoring is a fixed monthly rate for 7 pre-selected metrics, updates every 1 minute

### Some Takeaways

* Amazon EC2 enables you to run Windows and Linux virtual machines in the cloud.
* You launch EC2 instances from an AMI template into a VPC in your account.
* You can choose from many instance types. Each instance type offers different combinations of CPU, RAM, storage, and networking capabilities.
* You can configure security groups to control access to instances (specify allowed ports and source).
* User data enables you to specify a script to run the first time that an instance launches.
* Only instances that are backed by Amazon EBS can be stopped.
* You can use Amazon CloudWatch to capture and review metrics on EC2 instances.

### Amazon EC2 pricing models

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FJJd1RjhHJPk7ZZwOnsCw%2Fimage.png?alt=media&amp;token=e15ffc39-cf57-46bb-baf2-d1c381e7ae04" alt=""><figcaption></figcaption></figure>

### Benefits and Use Cases for Each Model

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FdTmhUSNw3lCJF98J6uEc%2Fimage.png?alt=media&amp;token=37302f93-440b-44b4-b974-d49a4ab34adf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FOjBKG3h4EGspnWiitP1y%2Fimage.png?alt=media&amp;token=23620fc0-53ed-4795-874e-1f406122a732" alt=""><figcaption></figcaption></figure>

### The Four Pillars of Cost Optimization

* **Right size**&#x20;
  * Provision instances to match your needs
  * CPU, memory, storage, and network throughput
  * Select appropriate instance types for your use
  * Watch metrics on Amazon CloudWatch

{% hint style="success" %}
Best practice: Right size, then reserve
{% endhint %}

* **Increase elasticity**&#x20;
  * Stop or hibernateAmazon EBS-backed instances that are not actively in use ( non-production development or test instances )
  * Use automatic scaling to match needs based on usage
* **Optimal pricing model**&#x20;
  * Use the right pricing model for your use case and combine purchase types to fully optimize
  * Use On-Demand Instance and SpotInstancesfor variable workloads
  * Use Reserved Instances for predictable workload

{% hint style="info" %}
You could probably also use AWS Lambda (functions) for some tasks
{% endhint %}

* **Optimize storage choices**
  * Reduce costs while maintaining storage performance and availability
  * Save money by resizing EBS volumes, changing volume types, deleting EBS snapshots that are no longer needed
* Amazon S3 storage options with lifecycle policies can reduce costs

{% hint style="success" %}
Defining and enforcing cost allocation tagging can help improve costs
{% endhint %}

### Containers

* Repeatable
* Self-Contained environement
* Software runs the same in different environements
* Faster to launch and stop than VMs

> Containers are often compared to virtual machines (VMs). Like virtual machines, containers allow you to package your application together with libraries and other dependencies, providing isolated environments for running your software services
>
> \~ Google Cloud

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2F0kjlZ6mY1N2un9WZFQPL%2Fimage.png?alt=media&amp;token=cef89b66-1e52-429a-9778-ed93b3893cd4" alt=""><figcaption></figcaption></figure>

### What is Docker

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FhLzRQsH6Gx5NojzWNSos%2Fimage.png?alt=media&amp;token=ec4848cd-45cd-4bd2-8732-bedba725de2e" alt=""><figcaption></figcaption></figure>

### Amazon Elastic Container Service (Amazon ECS) <img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FwxvZb7LOMzCMKT0ufj7T%2Fimage.png?alt=media&amp;token=d7692a43-4474-4104-a406-eb29b7cd3159" alt="" data-size="line">

* Orchestrates the running of Docker containers
* Maintains and scales the fleet of nodes that run your containers
* Removes the complexity of standing up the infrastructure

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FdiTX42pppucgxp1Su5mW%2Fimage.png?alt=media&amp;token=2a2470e7-212f-4bc6-8936-3626765139c5" alt=""><figcaption></figcaption></figure>

### AWS Lambda

* It supports multiple programming languages
* Completely automated administration
* Built-infault tolerance supports the orchestration of multiple functions
* Pay-per-use pricing

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FtFoyGquf6LV0Xy1l49bK%2Fimage.png?alt=media&amp;token=f36a928b-7260-4906-8906-a54bcebb4888" alt=""><figcaption></figcaption></figure>

### Some Takeaways

* Serverless computing enables you to build and run applications and services without provisioning or managing servers.
* AWS Lambda is a serverless compute service that provides built-in fault tolerance and automatic scaling.
* An event source is an AWS service or developer-created application that triggers a Lambda function to run.
* The maximum memory allocation for a single Lambda function is 10,240 MB.
* The maximum run time for a Lambda function is 15 minutes

### AWS Elastic Beanstalk

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FVzP80ByTZJSo56xPGpLF%2Fimage.png?alt=media&amp;token=c3b0440b-b6ee-4f2f-86eb-3a6ea55867df" alt=""><figcaption></figcaption></figure>

* It supports web applications written for common platforms: Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker
* You upload your code
  * Elastic Beanstalk automatically handles the deployment
  * Deploys on servers such as Apache, NGINX, Passenger, Puma, and Microsoft Internet Information Services (IIS)

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2FzKYZyCJ8iHoMSh0mWwZy%2Fimage.png?alt=media&amp;token=e10cbe74-2044-4978-a246-ce05ed83356a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://739099499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlOjiOVl4TnmLMyvNNyQJ%2Fuploads%2F4EYt7aBKgOHxPVW5QYPk%2Fimage.png?alt=media&amp;token=4d248c4b-de3d-4f65-978c-e4e7fcf4db36" alt=""><figcaption></figcaption></figure>
