How to deploy the Upstash Rate Limiting template through Azion
Preview
The Upstash Rate Limiting template helps you to implement rate limiting in a serverless environment, without requiring extensive manual setup. This template includes configurations for limiting requests and window limit.
It works in conjunction with Azion Edge Functions, being possible to adjust the initial setup based on the args. Additionally, this template creates a new GitHub repository that allows a continuous deployment workflow. This way, you’re able to further configure and customize the setup to attend to your needs, obtaining easy management and delivery of your personalized content.
Requirements
Section titled RequirementsTo start using this template, you need to:
- Create an Upstash account.
- Create a Global Database for the best available edge latency in the Upstash Console.
- Generate your GitHub personal token.
Getting the template
Section titled Getting the templateTo start using the Upstash Rate Limiting template, proceed as follows:
- Access Real-Time Manager (RTM).
- If you don’t have an account yet, visit the sign-up page.
- On the homepage, select the Start with a template option.
- Find the Upstash Rate Limiting card and select it.
- Click the Settings tab to open the configuration form.
Setting up the template
Section titled Setting up the templateIn the configuration form, you must provide the information to configure your Azion application. Fill in the presented fields.
Fields identified with an asterisk are mandatory.
- Application Name *: the name of your edge application. It’s used to identify and manage your application within Azion’s platform.
- Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
- Upstash Redis Rest URL *: the URL to access your Upstash database using REST.
- Go to your Upstash Console and copy the
UPSTASH_REDIS_REST_URL
in your database page.
- Go to your Upstash Console and copy the
- Upstash Redis Rest Token *: the token to authorize access to your Upstash database using REST.
- Go to your Upstash Console and copy the
UPSTASH_REDIS_REST_TOKEN
in your database page.
- Go to your Upstash Console and copy the
- Limit Request: the maximum number of requests. Example:
6
. - Window Limit: the time window for new requests. Example:
10 s
(can be used: “ms” | “s” | “m” | “h” | “d”). - GitHub Personal Token *: your GitHub personal token.
After filling in all the information, click the Next button, located in the bottom-right corner. This will start the deployment process.
Deploying the template
Section titled Deploying the templateDuring the deployment, you’ll be able to follow the process through a window showing off the logs. When it’s complete, the deployment page appears, confirming the edge application has been successfully created.
This page shows you the following sections:
- Access your Edge Application section includes the link to visit and explore your edge application.
- Build Summary contains the application’s name and function.
- The Deployment details tab can be opened to access the logs related to the deployment.
- What do you want to do next? provides recommendations regarding advanced options to enhance your edge application: Customize Domain, Manage Edge Application, View Edge Application Metrics, View Edge Application Logs, and the Back to Home button.
Key configurations
Section titled Key configurationsThe Upstash Rate Limiting template creates a new Azion edge application and its domain. It also creates an edge function, to provide the arguments for the rate limiting, and a new repository in your GitHub account based on a public template.
In this function, the upstash/redis
and upstash/ratelimit
libraries are integrated, connecting to your Upstash Global Database and checking in the /login
route if it’s within the configured Window and Limit. The key for limits is metadata ["remote_addr"]
.
Additionally, to guarantee the optimal performance of this template, it’s necessary to activate the following Azion product:
You must activate this product separately via RTM. To do so:
- Access RTM.
- On the upper-left corner, select the three horizontal lines to open the Products menu.
- In the BUILD section, select Edge Application. You’ll be redirected to the Edge Application page.
- It lists all the edge applications you’ve created.
- Find the edge application related to your template and select it.
- In the Main Settings tab, find the Edge Application Modules section and active the switch for the product you want to enable.
Managing your project
Section titled Managing your projectConsidering the initial setup may not be optimal for your specific web application, all settings can be customized any time you need using Azion Real-Time Manager (RTM). Once the template is deployed, you also have full control over customizing your Upstash account and database.
To manage and edit your edge application’s settings on Azion, follow these steps:
- Access RTM.
- On the upper-left corner, select the three horizontal lines to open the Products menu.
- In the BUILD section, select Edge Application. You’ll be redirected to the Edge Application page.
- It lists all the edge applications you’ve created.
- Find the edge application by the name you defined during the template execution and select it.
- The list is organized alphabetically. You can also use the search bar located in the upper-left corner of the list; currently, it filters only by Application Name.
After selecting the edge application you’ll work on, you’ll be directed to a page containing all the settings you can configure.
Continuous deployment
Section titled Continuous deploymentThe template args can also be updated and it’s possible to implement a continuous deployment workflow. However, you’ll need first to declare secrets on your project’s GitHub repository to successfully complete the second build with the changes. Once this second build is completed, you’ll be able to manage your project with a continuous deployment workflow and edit the args as desired.
To do so, open your Upstash Rate Limit repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:
- Add the Azion personal token to the secrets:
- Read how to generate an Azion Personal Token in the documentation.
AZION_PERSONAL_TOKEN=<value>
- Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
- name: edge-... id: azion_edge ... with: .... azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }} ....
- Add the Redis Database access credentials to the secrets, being:
- UPSTASH_REDIS_REST_URL: the URL to access your Upstash database using REST.
- Go to your Upstash Console and copy the
UPSTASH_REDIS_REST_URL
in your database page.
- Go to your Upstash Console and copy the
- UPSTASH_REDIS_REST_TOKEN: the token to authorize access to your Upstash database using REST.
- Go to your Upstash Console and copy the
UPSTASH_REDIS_REST_TOKEN
in your database page.
- Go to your Upstash Console and copy the
- UPSTASH_LIMIT: the maximum number of requests. Example:
6
. - UPSTASH_LIMIT_WINDOW: the time window for new requests. Example:
10 s
. (can be used: “ms” | “s” | “m” | “h” | “d”).
UPSTASH_REDIS_REST_URL=<value> UPSTASH_REDIS_REST_TOKEN=<value> UPSTASH_LIMIT=6 UPSTASH_LIMIT_WINDOW=10 s // "ms" | "s" | "m" | "h" | "d";
- Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
- name: Create args file run: | ... "UPSTASH_REDIS_REST_URL": "${{ secrets.UPSTASH_REDIS_REST_URL }}", "UPSTASH_REDIS_REST_TOKEN": "${{ secrets.UPSTASH_REDIS_REST_TOKEN }}", "UPSTASH_LIMIT": "${{ secrets.UPSTASH_LIMIT }}", "UPSTASH_LIMIT_WINDOW": "${{ secrets.UPSTASH_LIMIT_WINDOW }}" ...
- Open a pull request with the changes to the main branch and start the automatic deployment.
Now, your project is ready to work with a continuous deployment workflow, updating instantly any changes in the application or the repository.
Adding a custom domain
Section titled Adding a custom domainThe edge application created during the deployment has an assigned Azion domain to make it accessible through the browser. The domain has the following format: xxxxxxxxxx.map.azionedge.net/
. However, you can add a custom domain for users to access your edge application through it.
Contributors