Deploing to AWS


AWS EC2 instances can be used to run Zenaton workers. The following example will show you how to deploy your code to a Linux-based EC2 instance and have it execute your workflows and tasks. You will see how to:

Create an instance and set the security to allow your Agent to talk with Zenaton
Install the files needed to run Zenaton, and to execute your Workflows, and your Tasks.
Set you Agent to automatically run when the EC2 instance is started.

For this example, we will use a Linux-based instance. Specifically, the "Amazon Linux 2 AMI (HVM), SSD Volume Type" was used. Any version with systemctl installed should work, though you may need to change some of the file paths.

After selecting your AMI, you will be able to select your Instance Type. This example used the t2.micro, which is also free tier eligible.

Steps 3 (Instance Details), 4 (Storage), and 5 (Tags) can be set how you wish, though the defaults will all work. For Security, however, you will need to add two rules. You will need to allow outbound traffic from ports 443 and 5672. You can read more about this here.

aws-ports

You can now launch your instance. Download the SSH key if needed, and make note of the Public DNS. Use that information to log into your new instance:

ssh -i <path to key> ec2-user@<public dns>

Once logged in you'll want to update any packages that may be out of date.

sudo yum update
curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum -y install nodejs

Next, install Zenaton:

curl https://install.zenaton.com | sh

Now you can copy your project to your instance. Create a directory for it:

mkdir app

And then use scp to copy your files from your computer:

scp -i <path to key> -r app/* ec2-user@<public dns>:app/

Now you can log back into your instance, and install your project's dependencies:

cd app
npm install

Your project can now be run on your instance. Just make sure you have a valid .env in your project directory. All that remains is to set it to automatically start when your instance is launched. We will do this using systemd. As root (ie, via sudo), create the service file at /etc/systemd/system/zenaton-agent.service:

[Unit]
Description=Zenaton Agent Daemon service
After=network-online.target

[Service]
Type=forking

# User and group that will be used to run your Zenaton Agent. User must have a Zenaton Agent installation
# in its home directory and have correct permissions to execute your sources.
User=ec2-user
Group=ec2-user

# Path to sources of your workflows & tasks.
WorkingDirectory=/home/ec2-user/app

# Add your exact listen command
ExecStartPost=/usr/local/bin/zenaton listen --boot=boot.js --env=.env

ExecStart=/usr/local/bin/zenaton start
ExecStop=/usr/local/bin/zenaton stop
Restart=always

[Install]
WantedBy=multi-user.target

Finally, start the Agent, and tell systemd to start it each time your instance is launched:

sudo systemctl daemon-reload
sudo systemctl start zenaton-agent
sudo systemctl enable zenaton-agent

Your instance will now execute your Workflows and Tasks. To test, you can start Zenaton locally in client mode, and check zenaton.out on your EC2 instance to verify the tasks are being executed on the instance.