What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.
Software Development

Getting Started with wasmCloud

How to run Web apps with WasmCloud
Sep 17th, 2021 10:00am by
Featued image for: Getting Started with wasmCloud

WasmCloud is a platform that aims to help developers create secure, portable, and reusable components (called actors). It leverages WebAssembly for extreme portability so you can secure, deploy, maintain, observe, and upgrade software, all while reducing the amount of boilerplate that must be copied and pasted.

WasmCloud was designed, from the ground up, around these five core ideas:

  • Productivity
  • Enterprise-grade security
  • Cost-effectiveness
  • Portability
  • Performance

If you’re just now hearing about WebAssembly, make sure to first read the following pieces: What Is WebAssembly and Why Do You Need It?, Build a WebAssembly App with Rust, and How to Compile C code into WebAssembly with Emscripten.

To finish up out series on WebAssembly, we’re going to walk through the first steps of using wasmCloud.

I’ll be demonstrating on Ubuntu Server 20.01, but you should be able to follow along with any Debian-based distribution, any Linux distribution that supports snap, Fedora, or macOS (but not M1 macs).

With that said, let’s get to the installation.

Installing Rust

Before we install wasmCloud, let’s first install Rust. It’s not an absolute dependency, but it is recommended. Log into your Linux server, open a terminal window, and install Rust with the command:

curl --proto '=https' --tlsv1.2 -sSf | sh

When prompted, type 1 for Proceed with installation (default) and hit Enter on your keyboard. The installation of Rust should complete without any errors. When the installation is finished, you’ll then need to source the environment variables for Rust with the command:

source $HOME/.cargo/env

At that point, Rust is installed and ready to go.

Installing wasmCloud

Now we can install wasmCloud. The first thing to be done is to add the necessary repository for the software. To do that, go back to your terminal window and issue the command:

curl -s | sudo bash

That command should also update apt for you. If it doesn’t, you can do it manually with the command:

sudo apt-get update

Once apt has been successfully updated, install the necessary wasmCloud software with the command:

sudo apt-get install wasmcloud wash -y

Getting Started with wasmCloud

With wasmCloud installed, you’re ready to fire up your first wasmCloud host. Do this with the command:

wash up

Your terminal will be split into four panes (Figure 1).

Figure 1: The wasmCloud instance has been brought up and is ready to be used.

This is a preconfigured wasmCloud host. Your terminal window should be sized to a minimum of 250×50 characters, otherwise, you’ll have to deal with line wrap, which will make everything a bit confusing. It’s also important, as you deploy your actors and providers, that you make note of the IDs of each (found in the bottom right pane) as they deploy. Retrieving those IDs after the fact can be challenging, as they will be truncated.

To view the running hosts, issue the command:

ctl get hosts

The output of the command should list a single host ID and the uptime (in seconds) for that host. To get a list of the inventory of a host, issue the command:

ctl get inventory ID

Where ID is the host ID.

The next thing we’re going to do is run our first actor. WasmCloud has provided a handy Echo sample actor (which merely echos input) to use, which can be started with the command:

ctl start actor

Once you’ve started the actor, you should see the progress in the top-right pane, which will state Actor starting on host ID (where ID is the ID of the host). The Echo actor only includes a single operator, which is to respond to delivered HTTP requests and will echo the request sent. But in order for this to work, we have to start the HTTP Server provider with the command:

ctl start provider

Now, let’s view the host inventory again with the command:

ctl get inventory ID

Where ID is the host ID.

This time you should see both the Echo actor and the HTTP provider included (Figure 2).

Figure 2: Our Echo actor and HTTP provider are now running on the host.

Now that we have both the actor and provider started, we have to connect them so they can function properly. For this, you’ll need the Actor ID and Provider ID (which you should have copied down as each was deployed).

To connect these two together, the command will be:

ctl link ACTORID PROVIDERID wasmcloud:httpserver PORT=8080

Where ACTORID is the ID of the Echo actor and PROVIDERID is the ID of the HTTP provider.

You should see something like:

Advertised link (MBCF) <-> (VAG3) successfully

Let’s interact with our newly-linked actor. Open a second terminal to your hosting server and issue the command:

curl localhost:8080/echo

You should see returned:

That’s a successful call to your linked actor and provider.

To exit out of the wasmCloud console, just type exit and you’re out. Just remember, once you exit, your actors and providers will no longer be available (so you’ll have to deploy them again if you want to use them).

Congratulations, you’ve taken your first steps with wasmCloud. To learn more about this powerful tool, check out the wasmCloud App Development documentation.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.