🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Active Job is a framework for declaring jobs and making them run on a variety of queuing backends. In this post we’ll be setting up a worker environment on Elastic Beanstalk and using SQS as our Active Job queue.

We’ll be using the active-elastic-job to do the heavy lifting for us, so this post will be mostly focussed on the configuration to get this Gem working.

Our first port of call will be Simple Queue Service in our AWS account. We’ll need to create a new queue:

Create a new SQS Queue.

Now we have our queue we need to give our Elastic Beanstalk environments access to it. If we look at our existing environment we can see that it was created with an instance profile:

Instance Profile

In my case the profile is called aws-elasticbeanstalk-ec2-role. Make a note of this profile name and go to IAM users. Goto the roles tab and find the matching role. You now need to attach a policy to the role that allows access to SQS. In this demo we just use the SQS full access policy, but you may want to create a new policy that limits access to the queue you just created.

Instance Profile

The active-elastic-job needs to know which region we are running in so we need to add an AWS_REGION environment variable. For my region this will be eu-west-1 you may be running in a different environment so check what your region is called.

Instance Profile

We are now ready to create our worker environment. Goto your application and in the actions drop down click Create Environment

Instance Profile

For the environment tier - pick Worker environment:

Instance Profile

Make sure to pick Ruby as your Platform and then click Configure more options. On the next screen make sure to change the platform configuration to match your web server environment.

Instance Profile

Select Puma

Modify the Environment Settings to give your new environment a sensible name (e.g. demo-worker).

Modify the Sofware and copy across the following environment variables from your web env - DATABASE_URL (so we can connect to the database), SECRET_KEY_BASE (so we can encrypt and decrypt the same data) and AWS_REGION (so the active-elastic-job Gem knows which region we are in).

We also need to switch on processing of job in this environment. To do this we need to add PROCESS_ACTIVE_ELASTIC_JOBS and set it to true.

Check the Security to make sure the IAM instance profile matches the one we modified for SQS access.

And finally open the Network tab and select our VPC, choose our private subnets and the webserver security group (the webserver security group gives access to the PostgreSQL database).

You can now click Create Environment.

On the rails side we need to tell Active Job to use our active-elastic-job queue adapter. Add the active_elastic_job to our Gemfile and run bundle install. Now edit:

# config/environments/production.rb
config.active_job.queue_adapter = :active_elastic_job

In our Rails application create an Active Job by running

rails generate job capitalise_name

And in the code for our job set the queue_as property to the name of the queue we created e.g:

class CapitaliseNameJob < ApplicationJob
  queue_as :active_job_demo

  def perform(person)
    person.capitalized_name = person.name.capitalize
    person.save!
  end
end

And you can now add calls to this job in your code e.g:

CapitaliseNameJob.perform_later @person

Deploy the changes out to your web environment:

eb deploy --profile demo

And then deploy the same code out to your new worker environment:

eb use demo-worker --profile demo
eb deploy --profile demo

You can switch between different environments using (assuming your environments are name demo-web and demo-worker:

eb use demo-web --profile demo
eb use demo-worker --profile demo

Your ActiveJobs should now run successfully in your worker environment. If you have issues then check the elastic beanstalk logs on each environment:

eb use demo-web --profile demo
eb logs --profile demo
eb use demo-worker --profile demo
eb logs --profile demo

Related Posts

Step 4: Deploy Rails App To Elastic Beanstalk from Command Line - This post guides you through the essential steps of creating and deploying a Rails application into Elastic Beanstalk environment. Topics include creating an AWS user, configuring AWS CLI for deployment, and setting up the environment variables for your app. Also, it provides you the valuable knowledge of connecting your Rails app to RDS instance and ensuring it successfully connects with the dev database.
Step 1 - Setup VPC: Deploying a Rails Application to Elastic Beanstalk - In this blog post, I am guiding you through the process of deploying a Rails application to Elastic Beanstalk in a Virtual Private Cloud (VPC) on Amazon AWS. I detail the setup of a VPC, subnets, and internet gateways, as well as the configuration of NAT gateways and security groups. Ultimately, this will allow for a safe, internet-accessible environment for your application and its accompanying databases.
Step 2 - Setup Elastic Beanstalk: Deploying a Rails Application to Elastic Beanstalk - In this post, I describe how to set up, configure and deploy an Elastic Beanstalk application on a VPC in Amazon AWS, using Rails 5 and Ruby, using Puma for deployment and configuration of Public and Private subnets in Elastic Load Balancer. I also cover the details of network card settings, the selection process for subnets and security groups for Load Balancer and Instances, and finally shared the result of deploying the sample application on Elastic Beanstalk.
Step 5: Use CircleCI to Deploy To Elastic Beanstalk - In this blog post, we're going to set up an automated deployment pipeline using CircleCI, GitHub, and AWS Elastic Beanstalk. We'll begin by creating a GitHub repository for our Rails application. Next, we're going to help CircleCI understand our build environment by creating a `circle.yml` file to install the AWS EB CLI tools and to define commands for deploying our application. Lastly, we'll set up the required AWS credentials in CircleCI. Once completed, any changes pushed to the develop or master branch in GitHub will trigger a deployment to the respective environment in Elastic Beanstalk.
Step 6: Add a Custom Domain and SSL to Elastic Beanstalk - In this post, we successfully set up a custom domain name for our Elastic Beanstalk environment and secured it using SSL. By creating a CNAME or an ALIAS pointing at our environment URL (found on the dashboard screen), we made our app accessible via the new domain name. We then used AWS Certificate Manager to add SSL to our environment for access over HTTPS, which was confirmed by visiting the secured site. Now we have a Rails application that can not only be deployed by a CI server, but is also SSL secured with a custom domain.

Related Videos

ESP32-S3 - Which Pins Are Safe To Use? - In this video, I've decided to dive deep into the ESP32-S3, a module ruling my lab recently due to its plug-in-and-play functionality, and the flexibility offered by its GPIO matrix. However, working with it requires vigilance, especially with regard to the strapping pins and USB data pins, among others. Discovering such quirks, I've encountered unexpected values, short glitches and the occasional code crash. To help you avoid these bumps, I've documented everything I've learned on my GitHub repo, where I'm inviting you, my fellow makers and engineers, to contribute your valuable experiences and findings. After a minor hiccup with my ESP32-TV, expect an updated PCB design, courtesy of PCBWay. Explore the ESP32-S3 with me, and let's unravel its secrets together, one pull request at a time.
How to make your ESP32-S3 code faster. - I put my ESP32-S3 dev board from PCBWay through a quick performance workout by decoding a baked-in animated GIF with Larry Bank’s decoder and tweaking ESP-IDF settings. Cranking the CPU to 240MHz gave the expected ~1.5× bump, -Os beat -O2, switching flash from DIO to QIO shaved a bit more, and turning the caches up to 11 pushed it further. Best combo: 240MHz, -Os, QIO, max caches (with a larger partition and watchdog off). Nice little speed win.
A Lot of Hot Air - Soldering ESP32-S3 Boards - In this video, I test out the new hot air rework station I just got to solder my Mini esp32 S3 boards. I dissect the hot air gun, encountering an Australian plug and a couple of interesting quirks inside the control PCB. I attempt to understand the circuit, welcome your thoughts on the build quality, and then solder on a new, hopefully safer, UK-compliant plug. Post-assembly, I apply way too much solder paste thanks to these tricky solder syringes, before setting the station to 300 degrees C for some hands-on rework. After some trials, I successfully fix some solder bridges with my soldering iron and behold, everything is connected and it works! It's just another blink sketch, but hey, it's confirmed – The new hot air station works!
Three ESP32 Rainbow Boards Failed QA — Can we fix them? - I’m assembling another batch of ESP32 Rainbows: PCB house does the boards, UV silkscreen and some parts, and I finish assembly and QA here in Scotland. I run through three QA fails—no sound, dodgy keyboard, and no USB—then fix two: the audio fault was lifted pads on the headphone jack, so I bodged it back with flux and solder (speaker and headphones now work, but it’s a spares board). The no‑USB issue was an ESD protection IC sitting off its pad; I reflowed it on a mini hot plate, cleaned up with IPA, verified continuity, and it now enumerates and flashes perfectly. On to the keyboard next—oh, and Happy New Year!
Taking KiCad Silk Screen to the Next Level! - Take a peek at how my ESP 32 ZX Spectrum project is coming along! We're funded on Crowd Supply, ordering components, and adding a cool silk screen design to our PCB. Using tools like KiCad and Affinity Designer, I've jazzed up the back of the board with detailed graphics. It's been an exciting journey, making adjustments and ensuring everything works perfectly before ramping up production. If you haven't yet, head over to Crowd Supply and support the ESP 32 Rainbow project!
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts