How to use Upstash GeoLocation through Azion

Preview

Upstash GeoLocation is an automation designed to deploy a database directly on the edge while enabling the configuration of custom messages that will be delivered according to the user’s geographical location.

These messages are delivered through a static interface, based on HTML and generated by the template after deployment.


Before using this template, you need to:

  1. Create an Upstash account.
  2. Create a Global Database for the best available edge latency in the Upstash Console.
  3. Generate your GitHub personal token.

You must also activate:

Edge Functions


Application Accelerator

You need to activate these modules via Azion Console. To do so:

  1. Access Console > Account menu
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for each module.

To get this template, access Azion Console and select the Start with a template option on the homepage.

This will open a new page where you can select the Upstash GeoLocation card.


In 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.
  • 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.
  • GitHub Personal Token *: your GitHub personal token.

After completing all the information, click the Next button, located in the bottom-right corner. This will start the deployment process.

During 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 for your project 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.

Upstash GeoLocation EdgeDeploy creates a new Azion edge application and its domain. It also creates an edge function to provide the arguments for the geolocation, a new repository in your GitHub account based on a public template, and a static interface to show the messages.

In this function, the upstash/redis library is integrated, connecting to your Upstash Global Database and retrieving the message based on the user’s location. This location is taken from the metadata ["geoip_country_code"].

The template also incorporates location-based greetings in your database, which are retrieved from the integration with Upstash, similar to this:

Terminal window
Welcome to Upstash CLI
set BR "Olá, tudo bem!"
OK
set GB "Ey up?"
OK
set US "Yo, what's up?"
OK
set IN "Namaste"
OK

You can customize these greetings on your Upstash database to attend to your necessities.

To know more on how to edit and customize your project’s settings, go to the Managing your project on Azion section.


Managing your project on Azion

Section titled Managing your project on Azion

Considering that this initial setup may not be optimal for your specific edge application, all settings can be customized any time you need by using Azion Console. 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, follow these steps:

  1. Access Console.
  2. On the upper-left corner, select Products menu > Edge Application.
  • You’ll be redirected to the Edge Application page. It lists all the edge applications you’ve created.
  1. Find the edge application related to the Upstash GeoLocation template 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.

Once the template is deployed, you can edit and update your args and code in the edge function, as well as implement a continuous deployment workflow. However, you’ll need first to declare secrets on your project’s GitHub repository to complete the second build with the changes. When the second build is finished, 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 GeoLocation EdgeDeploy repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:

  1. Add the Azion personal token to the secrets:
Terminal window
AZION_PERSONAL_TOKEN=<value>
  1. Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
.github/workflows/main.yml
- name: edge-...
id: azion_edge
...
with:
....
azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }}
....
  1. 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.
  • 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.
Terminal window
UPSTASH_REDIS_REST_URL=<value>
UPSTASH_REDIS_REST_TOKEN=<value>;
  1. Add the environments for use in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
.github/workflows/main.yml
- name: Create args file
run: |
...
"UPSTASH_REDIS_REST_URL": "${{ secrets.UPSTASH_REDIS_REST_URL }}",
"UPSTASH_REDIS_REST_TOKEN": "${{ secrets.UPSTASH_REDIS_REST_TOKEN }}",
...
  1. Open a pull request to merge 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.

The 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.

go to Domains reference

Contributors