Was this article helpful?
Thanks for your feedback
In this guide, we will look at the steps required to create an automated system for scheduling repeatable releases using AWS Lambda and Contentstack's Content Management APIs.
Once the system creates a release automatically, you can add items (entries and assets) to it and they will be deployed automatically on the scheduled time. This is a continuous process where the release gets created every day and if there are items added to it, they get deployed.
In this example, we will use two Lambda Functions: one for creating a release and another one for deploying the release. The “create” release lambda function will create a new release for every new day. For example, a release will be scheduled every midnight after 12:00 AM, a new day, and create a release for this specific day using the Releases API.
Note: The date can be changed as per your convenience, but ensure that it is after 12:00 AM or a new date 00:01 (24 hr format).
In the following image, you can see that release Thu May 14 2020 is the release name and created by using the Create Release Lambda Function every new day for entries and assets required to be deployed on that day, that is, “Thu May 14 2020.”
The Deploy Release Lambda Function deploys the release created on that specific date. For example, if the release is scheduled for “Thu May 14 2020,” the Deploy Release lambda will look for a release created for that day.
If it finds the release for that day, it fetches the UID of that release and looks for any entries or assets within that release. And if there are any entries or assets within that release, it deploys the release. If there are no entries or assets for deployment in the release, it does nothing as there is nothing to deploy.
The next day, the Create Release lambda function will be triggered again to create another release. And this continues making it repeatable. If the release with entries and assets is deployed, it locks the release (as shown in the above screenshot) and it cannot be accessed for adding new entries or assets (it will be disabled).
Note: These lambda functions can be “enabled” or “disabled” to stop lambda from creating and deploying releases.
Let's now move ahead with the steps and create the required system.
Go to our GitHub page and download the code for the Create Release and Deploy Release lambda functions.
After downloading the code, fire up the terminal, go to the respective project directories, and install the required node modules using the npm install command.
Perform the following steps to set up the Create Release Lambda function:
With these steps, we have set up our Lambda Function. Let's now move ahead with creating a trigger for this Lambda Function.
We will add a trigger to our lambda function to invoke it at a particular time. We do this as follows:
Additional Resources: Refer to Cron-Generator and AWS-guide-on-using-cron for more information. Also, refer to the AWS guide on How-to-schedule-lambda-using-cloudwatch-events.
For the Create Release Lambda Function, the scheduled cron expression that we just set will trigger on cron(00 01 * * ? *), that is, at 1:00 AM (which will be on a new day). You can adjust the scheduled cron expression but make sure it is on a new date, that is, after 12:00 AM.
Note: You can use cron or rate expression to create self-trigger rules on an automated schedule in CloudWatch Events. All your created scheduled events use the UTC time zone with the minimum precision of 1 minute for the schedule.
After you have set up the trigger, this is how it will look in the Lambda dashboard:
Note: You can disable or enable events rules using the options as shown in the above screenshot.
Perform the following steps to set up the Deploy Release Lambda function:
Note:If you plan to deploy your release on multiple environments, you can click on the Add environment variable button and add more environments. If you have added more environment for deployment make sure to add the name of those environments in the deployRelease code as shown:
With these steps, our Lambda Function for Deploy Release is configured. Let's now add a trigger to this lambda function.
We will add a trigger to our lambda function to invoke it at a particular time. We do this as follows:
Once the trigger is configured, it will look similar to this:
Note: You can disable or enable events rules using the options as shown in the above screenshot.
With these steps, we have the set up ready. On the scheduled time and date, the Create Release Lambda Function will be invoked to create a release.
Accordingly, the Deploy Release Lambda Function will be invoked as well at the scheduled time and it will lock the release.
Once the release is created, this is how appears:
Additional Resource: We have created various other guides that cover the use of AWS Lambda functions. You may refer to our Webhook Integrations page for more details.
Was this article helpful?
Thanks for your feedback