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

# Module 14

{% hint style="info" %}
Oonuh wan fi deal wit nuh serva
{% endhint %}

Using Microservices instead of full servers is much more efficient in regards to management and cost

Benefits:

* No server management
* Continuous scaling
* Pay-for-value services
* Built-in high availability
* Suitable for event-driven and microservice architectures

### AWS Serverless services

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FwobmlIjx4URbZQbIMYxF%2Fimage.png?alt=media&amp;token=4ab5c961-9a57-4839-bc46-abfb421c1102" alt=""><figcaption></figcaption></figure>

#### Example: Serverless Three-Tier Design

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FkXWT8cQRJlKSYwAxQERy%2Fimage.png?alt=media&amp;token=ff1d088d-bfb7-4167-9556-a90e1cfc4a0f" alt=""><figcaption></figcaption></figure>

### Microservices

{% hint style="info" %}
Microservices are autonomous and specialized in their field
{% endhint %}

#### Example of breaking down a big service into microservices

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FiMrrrA61VSVfiPcjAvv7%2Fimage.png?alt=media&amp;token=c0bb7cab-d503-4437-8d9c-6be85fcba76b" alt=""><figcaption></figcaption></figure>

### Lambda

* Simply compute code for a simple task. Same thing as Azure Functions
* Can be event-driven and even layerd

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FO6d98gi7qMdeJCjrpDIC%2Fimage.png?alt=media&amp;token=bc0a2f3d-f7ab-42ec-a214-cf05272892e4" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}

* No more than 15 minutes
* Workloads that use more than 10 GB of memory are not suitable for Lambda
* Containers can help migrate legacy applications
* The price to run a Lambda function increases with the number of invocations, duration, and memory allocated
* Containers can be continuously run at a fixed cost
  {% endhint %}

### AWS Step Functions

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FwwPWeV4Hpl4VZ431KcEW%2Fimage.png?alt=media&amp;token=ae605c3e-9e8c-4f99-8240-ecccc4470655" alt=""><figcaption></figcaption></figure>

* Is a serverless orchestration service to manage workflows between multiple AWS services
* Has state machines (workflows) that contain a series of event-driven states (steps)
* Manages each workflow’s state, checkpoints, and restarts
* Provides error handling capability
* Can transfer data between states\\
* States can filter and manipulate data

{% hint style="info" %}
Just like python story games. Depending on the the action/result different functions will be executed. All start with the initial task

{% endhint %}

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FTTw14AfI9USTZr3eCx1d%2Fimage.png?alt=media&amp;token=02d96e97-8b90-4cdb-8f3e-9d5d70324ea9" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Each one of these steps can be a Lambda function
{% endhint %}

#### Use cases

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F3D8wGEmvnHEmL6m58hN6%2Fimage.png?alt=media&amp;token=98ad08a5-63d9-4a02-893c-d575162afa03" alt=""><figcaption></figcaption></figure>

### Amazon API Gateway

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FCCtlgP7OemW1oMe3jfKp%2Fimage.png?alt=media&amp;token=54feb88b-8a15-4ce2-a4d0-0653a5f1e646" alt=""><figcaption></figcaption></figure>

* Provides the ability to create, publish, and maintain REST, HTTP, and WebSocket APIs
* Configurable traffic management, authorization, and resource access control
* Provides access to AWS services and publicly accessible endpoints
* Hosts multiple versions and stages of an application’s API
* Establishes client usage plans to monetize and control APIs •Can cache common responses

#### Benefits

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F2Od5O7SjxbqKyhr9snkr%2Fimage.png?alt=media&amp;token=01862cc7-28d0-40d6-89fc-3a085c09e561" alt=""><figcaption></figcaption></figure>

#### API Types

| Rest API's                                                                                                                           | HTTP API's                                  | WebSocket API's                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- | ---------------------------------------------------------------------------- |
| Collection of routes and methods                                                                                                     | Collection of routes and methods            | Collection of WebSocket routes                                               |
| For apps that require API management features, such as usage plans, payload validation, private API endpoints, and resource policies | For Microservices                           | For real-time applications                                                   |
| Supports cross-origin resource sharing (CORS                                                                                         | Suppors CORS                                | Establishes a session between client and backend services                    |
| Stateless                                                                                                                            | Lower latency and lower cost than REST APIs | API management features are validate payload schema and data transformations |
|                                                                                                                                      | Stateless                                   | Stateful                                                                     |

### API Gateway Backend Integration

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F5CuFLmuf91mROWDh3hJN%2Fimage.png?alt=media&amp;token=0f583c17-28fb-4e9a-ade3-506f8da4625d" alt=""><figcaption></figcaption></figure>

#### How a traditional application can be made better with Microservices and API Gateway

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2F1yyAyO2e0lUQ8ZGpKoxQ%2Fimage.png?alt=media&amp;token=8308eca4-246a-4285-be69-07a36a72f7de" alt=""><figcaption></figcaption></figure>

#### Shopping Cart

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FIqXTVZAVB9K2y1xXtP25%2Fimage.png?alt=media&amp;token=88de27b2-1681-4c0e-a8cc-fb10732f0cac" alt=""><figcaption></figcaption></figure>

#### Payments

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2FzBNZeDQVCtDlnQ6Fqcm9%2Fimage.png?alt=media&amp;token=2350123c-730d-49ed-9986-a15c0678d29f" alt=""><figcaption></figcaption></figure>

#### Delivery

<figure><img src="https://3899036363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsmRwCapKRPjknpALqp9Y%2Fuploads%2Fa9KWJwU9T0RBUYQ6JUFp%2Fimage.png?alt=media&amp;token=74051a6e-1646-4acb-8cb5-717afc3abab0" alt=""><figcaption></figcaption></figure>
