Scheduling website content is hard. Most content management systems (CMS) have features for publishing products, blog articles, and other types of platform-related content, but what about simply scheduling HTML? As developers sometimes we want to show a section of our website during a certain time frame. Think holiday sales or launch events. Surprisingly this is harder to pull off then one might think. You have to set up some sort of cron that triggers some function that publishes some piece of content. It can be tough to build! That's why I'm building newclick.io, a tool to help you schedule promotional content on your website. We're starting with something simple, announcement banners, but will soon branch out to different types of components. In this article, I'll briefly describe some of the things that went into developing the newclick.io Scheduling API.





Architecture ✏️

The first step was to figure out if this was even possible. How are developers scheduling content today? CMS platforms like Shopify and Wordpress allow users to set publish dates for things like products and blog posts, so it's definitely achievable, but certainly, they aren't using something like a crontab, are they? No way! It's 2020 we run things in the cloud these days so any type of server-side crontab would be out of the question. This included out of the box solutions such as the node-schedule and node-cron libraries. These wouldn't work with how I wanted to architect my servers. From the very beginning, I wanted to use the serverless framework and deploy to AWS Lambda. We didn't want to think about spinning up EC2 instances and worrying about uptime and other server-related things. I wanted to keep the development focused on code and less on infrastructure. I was also intrigued by the inherent costs savings you get with Lambda functions. You don't pay for idle server time, which made sense for my fledgling startup.





“So how am I going to pull this off?”, I thought. Well, I can't use a traditional server cron so I needed to look elsewhere. That's when I found AWS CloudWatch. CloudWatch is used for what AWS describes as “application and infrastructure monitoring”, but also provides tooling around scheduling crons and other event-related processes. “This is great!” I thought to myself. I could use CloudWatch along with the AWS JavaScript SDK to create our scheduled events. Onward!





Development 🛠

So with my new tool in hand, I was ready to start writing some code. I started by figuring out how to use the AWS SDK to interface with CloudWatch. First I needed to create a constant that would be available throughout our entire application. I started by defining and exporting a cloudwatchEvents service.