liveBook · Manning

Shell provisioner

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

A Packer provisioner that executes shell commands on a temporary build instance while creating an image.

A shell provisioner is a Packer build component that executes shell commands on a temporary EC2 instance before Packer captures the configured instance as an AMI. section 15.3

Preinstalling Etherpad

An inline shell script installs Node.js and Git, prepares /opt/etherpad-lite, clones a pinned Etherpad branch, and runs its dependency installer. Packer then stops the instance, creates the AMI, and terminates the temporary instance. section 15.3

Listing 15.8 The Packer template to build an Etherpad AMI, part 3
build {
  name    = "awsinaction-etherpad"
  sources = [
    "source.amazon-ebs.etherpad"                        #1
  ]
 
  provisioner "shell" {                                 #2
    inline = [
      "curl -fsSL https:/ /rpm.nodesource.com/setup_14.x
 | sudo bash -",                                      #3
      "sudo yum install -y nodejs git",                 #4
      "sudo mkdir /opt/etherpad-lite",
      "sudo chown -R ec2-user:ec2-user /opt/etherpad-lite",
      "cd /opt",
      "git clone --depth 1 --branch 1.8.17 https:/ /github.com/
 AWSinAction/etherpad-lite.git",                      #5
      "cd etherpad-lite",
      "./src/bin/installDeps.sh",                       #6
    ]
  }
}
#1 References the source; see listing 15.7.
#2 The shell provisioner executes a script on the temporary build instance.
#3 Adds a YUM repository for Node.js
#4 Installs Node.js and Git
#5 Fetches Etherpad from GitHub
#6 Installs Etherpad dependencies

Shows the shell provisioner syntax and the inline commands used to construct the Etherpad image. section 15.3

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

How deep it goes
Explains inline command execution and the surrounding image-build lifecycle without detailing provisioner internals.
Examples
Uses Node.js installation, Git installation, Etherpad cloning, directory preparation, and dependency installation as concrete commands.
What it assumes
Assumes Packer installation, plugin initialization, an EC2 source configuration, and an IAM role for Systems Manager connectivity.
What you can do after
Build it from scratch by defining inline shell commands that prepare an application image with Packer.
How it connects
Connects Packer provisioning with Amazon EC2, AMIs, AWS Systems Manager, CloudFormation, and Auto Scaling groups.

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.