liveBook · Manning

Server

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A web server is software that receives and responds to requests for web resources or application content.

A web server receives requests from customers or applications and returns web content or application responses. In a web shop, it handles customer requests while a database stores products and orders. On AWS, the server software can run on an EC2 virtual machine. section 1.2.1

To serve a default Apache website from an EC2 instance:

  • Launch an Amazon Linux 2 instance and allow HTTP traffic from the internet. section 3.5
  • Connect with Session Manager, then run `sudo yum install httpd -y`, `sudo systemctl start httpd`, and `sudo systemctl enable httpd`. section 3.5
  • Find the instance’s public IPv4 address in the EC2 console and open `http://$PublicIp` in a browser to check the default site. section 3.5

One instance is useful for a first deployment, but its public IPv4 address can change when the instance stops and starts. A load balancer gives clients a target to request without knowing a particular server’s address. It can check server health and forward requests to healthy instances; running servers in different data centers improves availability because an individual virtual machine is not highly available by default. section 3.5 section 1.2.3 section 14.0

A web server for image processing

A Node.js server built with Express provides a REST API: `POST /image` creates a process, `GET /image/:id` returns its state, and `POST /image/:id/upload` accepts an upload. Multiple EC2 instances run the server behind a load balancer, while separate workers process images. This keeps request handling distinct from the processing work. section 16.3.2

A web server need not deliver every asset itself. For a web shop, moving static content such as a logo to a content delivery network reduces server load, while the servers continue handling dynamic content such as products and prices. section 1.2.1

Listing 16.2 Creating an image process with POST /image
app.post('/image', function(request, response) {        #1
   const id = uuidv4();                                 #2
   db.putItem({                                         #3
    'Item': {
      'id': {
        'S': id                                         #4
      },
      'version': {
        'N': '0'                                        #5
      },
      'created': {
        'N': Date.now().toString()                      #6
      },
      'state': {
        'S': 'created'                                  #7
      }
    },
    'TableName': 'imagery-image',                       #8
    'ConditionExpression': 'attribute_not_exists(id)'   #9
  }, function(err, data) {
    if (err) {
      throw err;
    } else {
      response.json({'id': id, 'state': 'created'});    #10
    }
  });
});

The Express route shows a concrete server response: `POST /image` writes a new process to DynamoDB and returns its ID and state as JSON. section 16.3.2

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Walks through Apache setup and shows Express routes, without requiring an in-depth understanding of Express.
Examples
Demonstrates an Apache default website, a web shop, and an Express image-processing API.
What it assumes
Introduces EC2 launch and Apache setup step by step while treating detailed Express knowledge as unnecessary.
What you can do after
Operate/configure it on EC2 by installing and starting Apache, allowing HTTP traffic, and checking the site in a browser.
How it connects
Connects web servers to EC2, load balancers, databases, content delivery networks, REST APIs, and background workers.

Also explained in

Compare how 11 books explain server →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.