Skip to main content

Lab 7: Cloud Servers

Published

2026-12-02

This lab answers the comprehension questions from Chapter 7 of DO4DS (The Cloud). Lab 6 packaged the penguin model API in a Docker container on our local machine. Lab 7 moves that work to the cloud, where we rent servers and storage instead of running everything locally. The DO4DS labs get started with AWS by launching an EC2 instance, then put the penguins data and model in S3.

NoteAmazon Linux 2 in Labs 7 to 9

Labs 7 through 9 run on Amazon Linux 2 (AL2), which reached end of life on 2026-06-30. It still works for the SSH, user, and shell commands in these labs. Stand up an EC2 instance explains why we use it, and Lab 10 moves the instance to Amazon Linux 2023.

Comprehension questions

Going to the cloud

“What are two reasons you should consider going to the cloud?”

Two primary reasons to move to the cloud include:

  • The ability to rapidly increase or decrease computing resources to match demand without investing in physical hardware (i.e., scalability)
  • The cloud provider handles much of the underlying infrastructure management, such as hardware repairs, power, and cooling (i.e., reduce maintenance).

“What’s one reason you shouldn’t?”

One reason we might avoid the cloud is cost unpredictability. While we only pay for what we use, unmonitored usage or unexpected spikes in demand can lead to much higher monthly bills than anticipated.

Cloud service types

“What is the difference between PaaS, IaaS, and SaaS?”

The differences lie in how much of the technology stack we manage versus how much the provider manages:

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace', 'fontSize': '16px'}}}%%

graph LR
    subgraph "Responsibility"
        SaaS("SaaS: You manage<br>only usage")
        PaaS("PaaS: You manage<br>apps & data")
        IaaS("IaaS: You manage<br>OS, apps, &<br>data")
    end
    
    Provider(["Provider manages<br>infrastructure"]) --> SaaS
    Provider --> PaaS
    Provider --> IaaS
    
    style Provider fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style IaaS fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    style SaaS fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style PaaS fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    

Cloud acronyms

The table below covers other differences:

Acronym Model Responsibility
IaaS Infrastructure as a Service User manages OS, middleware, and apps
PaaS Platform as a Service User manages applications and data
SaaS Software as a Service User manages only usage

“What’s an example of each that you’re familiar with?”

Acronym Description Example
IaaS Provides raw computing resources like virtual servers and networking. Azure
PaaS Provides a framework for developers to build and deploy apps without managing the OS. Posit Connect Cloud
SaaS Delivers finished software applications over the internet. Teams

AWS services

“What are the names of AWS’s services for: renting a server, filesystem storage, blob storage?”

Setting Up AWS and S3

The DO4DS lab comes in two parts: getting started with AWS and putting the penguins data and model in S3. This book splits them into four chapters:

  1. Getting started with AWS: create an IAM group and user, an access key, and a dev-deploy profile for the AWS CLI on our local machine.

  2. Stand up an EC2 instance: create a key pair, a security group, and an IAM role. Then launch an Amazon Linux 2 (AL2) instance with the AWS CLI. DO4DS launches an Ubuntu instance from the Console instead. Lab 10 moves the instance to Amazon Linux 2023.

  3. Create S3 & Push/Pull Data: create the penguin-vetiver-model-data bucket and write the Python and R models to it with pins.

  4. GitHub Actions and S3: connect GitHub to AWS with OpenID Connect (OIDC). A workflow then publishes the models to S3 on every push to the lab07-s3 branch.

I’ve put the original files in the original/ folder, and separated the labs into original, R, and Python folders. The original files from the DO4DS _labs/lab7 folder are below:

original
├── docker
│   ├── app.py
│   ├── Dockerfile
│   └── vetiver_requirements.txt
├── model-vetiver-s3.qmd
└── publish-s3.yml

2 directories, 5 files
1
vetiver API that reads a fixed version of the penguin_model pin from the do4ds-lab S3 bucket (pins.board_s3())
2
Dockerfile generated by vetiver: starts from python:3.9 and runs the API with uvicorn on port 8080
3
Python packages for the API, pinned with pip-compile
4
Fits the linear regression model and writes it to the do4ds-lab S3 bucket with vetiver_pin_write()
5
GitHub Actions workflow that renders and publishes the site to gh-pages on every push to main, with AWS access keys stored as repository secrets

Recap

  1. The cloud is worth considering for scalability and reduced maintenance, but unmonitored usage can make costs unpredictable.

  2. IaaS, PaaS, and SaaS differ in how much of the stack we manage. With IaaS we manage the OS, apps, and data; with PaaS we manage apps and data; with SaaS we manage only usage.

  3. AWS’s services for renting a server, filesystem storage, and blob storage are EC2, EBS (or EFS for shared storage), and S3. The four chapters that follow launch an AL2 instance on EC2 and publish the models to S3, first by hand and then with GitHub Actions.

We’ll start by setting up IAM users and the AWS CLI in Getting started with AWS.