Rate limiting is a standard solution to many of these problems and should work out of the box.
Before use template, ensure that you have the following prerequisites:
- Azion account visit the sing-up page
- Upstash account (Sign up at Upstash)
To create an Azion account, just visit the sing-up page at Azion's homepage.
In order to use the template, you'll have to create a Upstash accpount to use with it. To do so, follow these steps:
- Create an Upstash account.
- Create a Global database for the best edge latency in Upstash Console.
To perform the deploy on edge, you have two ways to do:
- By using Marketplace.
- By using GitHub actions.
Build and Application choose a template
Choose Edge Application Upstash With Typescript template
Generate your personal github token by visiting the documentation at Creating a personal access token
Enter the information in the settings tab:
Application Name
: application name in Azion's RTM.Edge Function args
:JSON
args required for build and connection to redis database:- Example:
{ UPSTASH_REDIS_REST_URL: "", UPSTASH_REDIS_REST_TOKEN: "", UPSTASH_LIMIT: 5, UPSTASH_LIMIT_WINDOW: "10 s" }
Limit Request
: maximum number of requests. ex. 3Window Limit
: time window for new requests. ex. 1 "ms" | "s" | "m" | "h" | "d";
- Example:
Github Personal Token
: Github Personal Token.
Accessing your secrets Add Secrets
Create your Azion personal token by visiting the Personal Token creating page
Add the Personal Token to the secrets
:
AZION_PERSONAL_TOKEN=<value>
Environments for use in the action workflow:
- name: edge-...
id: azion_edge
...
with:
....
azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }}
....
Add the Redis Database access credentials to the secrets
:
UPSTASH_REDIS_REST_URL=<value>
UPSTASH_REDIS_REST_TOKEN=<value>
UPSTASH_LIMIT=6
UPSTASH_LIMIT_WINDOW=10 s // "ms" | "s" | "m" | "h" | "d";
Environments for use in the action workflow:
- 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 }}"
...
Note: for automatic deployment, create a pull request to the main branch.