Site iconAxway Blog

Amplify Central Custom API Subscription Approval Workflow Example Using API Builder – Hello World

Amplify Central Custom API Subscription Approval workflow

In the following two blog posts, we showed how to use API Builder and its flows to service Amplify webhooks and to make Amplify API calls as these are the two building blocks of integrating with Amplify:

In this blog post, we’ll put it all together and create a simple Amplify Central Custom API Subscription Approval workflow using an API Builder Flow. Note that we did the same thing using Amplify Integration Builder in this blog post so you can refer to that blog post for reference.

The API Builder API and associated flow that we’ll create will do the following:

The steps involved in doing this are shown below:

  1. Create the API Builder project
  2. Create a webhook handler API by importing a swagger that defines an Amplify webhook call
  3. Use the Amplify Unified Catalog API swagger definition to expose a connector in the API Builder Flow Editor
  4. Use the connector to make an API call to Amplify that will approve the API subscription request
  5. Configure Amplify to trigger a webhook to our API Builder API when an API subscription request is made by an API Consumer in the Amplify Unified Catalog

The first three steps were covered in the two blog posts referenced above. Refer to those blog posts for links to the Amplify Unified Catalog API swagger definition and any other assets mentioned below.

API Builder Flow

API Builder Flow
{
description: 'Approved via Custom Subscription Flow',
state: 'APPROVED'
}

My API Builder project can be found here for reference.

Configure Your Agent

As described previously, you need to configure your Amplify Central Discovery Agent to use subscription webhooks and configure your webhook to point to your app that services the subscription webhook event (the API Builder project you just created).

Edit your discovery agent environment file and make sure that CENTRAL_SUBSCRIPTIONS_APPROVAL_MODE is set to webhook and that the webhook URL and authentication headers are set (if required). In my example below, I am pointing to my API Builder project locally on my machine using ngrok and my API Builder project is set to use API Key authentication so, I do need to set an apikey header to the value of my API Key.

# Subscription configs
CENTRAL_SUBSCRIPTIONS_APPROVAL_MODE=webhook

CENTRAL_SUBSCRIPTIONS_APPROVAL_WEBHOOK_URL= https://be15-11-111-111-35.ngrok.io/api/amplifycentralwebhookhandler
CENTRAL_SUBSCRIPTIONS_APPROVAL_WEBHOOK_HEADERS=Header=apikey,Value=7JD........EF1g

Restart your discovery agent if it was already running so the changes will take effect.

Now when your API Consumer subscribes to an API, the subscription request will be approved automatically by the API Builder API.

You can now use this as a starting point for more robust custom API subscription approval workflows that implement your company’s API governance policies.

Summary

In this blog post, we combined the two components used in integrating with Amplify, namely Amplify integration webhooks and Amplify API calls, and created a simple custom Amplify API Subscription workflow in API Builder. This flow will auto-approve any API subscription request. While it’s simple, it leverages the elements that will be used in most integrations so it is a good starting point for learning how to leverage API Builder for Amplify integrations.

In future blog posts, we’ll cover more advanced use cases.

Learn more about Amplify Central Change Notifier.

Exit mobile version