Monetize API Gateway without using Marketplace

4

Would like to know if anyone of you has implemented monetization of your APIs hosted using API gateway without using the AWS SaaS Marketplace option? If yes which payment gateways did you use and what was the approach?

6 Answers
4
Accepted Answer

The main idea of monetizing the API is creating the infrastructure that supports it. There are two ways to approach this problem :

  1. The quick and native way (Using Data Exange, Product link, Data Provider Docs Link)
  2. And the Building blocks way

The Building blocks way

If there is a possibility on implementing the building blocks architecture there is a lot of flexibility on how this is built. First lets say a customer wants to integrate their on-premises with the Api-Monetization leveraging AWS to accomplish the task without the need of managing the infrastructure. Lets divide it into different topics to tackle:

Reference architecture here

  1. The developer Portal

For the Developer portal there are a couple of deployments in the server-less application framework,(Github, SAR) This solution is very complete and allows users to create a single place to administer the Public and Private endpoints, also administration of the versions of the different APIs and how are the end users going to register.


  1. The user portal/Api Monetization Portal

Now this part depends on the customer requirements, or regulations, because is where the user will see their charges/Usage, and will be able to pay, because customers are different depending on the region. This can be built with API Gateway referencing a DynamoDB table to keep track on the API consumption and finally integrate with the local/regional e-payment provider. Example DynamoDB api usage table would be

user-id;
timestamp;
body; cost;
email; 
httMethod;
Isbase64; 
path;
QueryStrings

Example DynamoDB api prices table would be

path; 
method; 
price; 
stage

Important things to note if you want to capture price changes/offers on the API is is ideal to capture cost per API call so if the price changes over time it would be easer to keep track of each user usage. This is an example code on how to track user usage using lambda

import json
import boto3
import datetime

def lambda_handler(event, context):
    headers = {'headers': {'Access-Control-Allow-Headers':'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token', 'Access-Control-Allow-Origin': '*'}}
    response_info = api_prices()
    prices = collapse_prices(response_info['Items'])
    dynamodb = boto3.client('dynamodb')
    email = event['requestContext']['authorizer']['claims']['email']
    name = event['requestContext']['authorizer']['claims']['name']
    username = event['requestContext']['authorizer']['claims']['cognito:username']
    event_copy = dict(event)
    
    # Deleting cognito token before storing it into dynamo
    del event_copy['headers']['Authorization']
    del event_copy['multiValueHeaders']['Authorization']
    
    # Storing request into dynamo
    response = dynamodb.put_item(
        Item={
            'user-id': {'S': username,},
            'timestamp': {'S': str(datetime.datetime.now().timestamp())},
            'httpMethod':{'S': event['httpMethod']},
            'path':{'S': event['path']},
            'resource':{ 'S': event['path']},
            "body":{'S': json.dumps(event['body'])},
            "isBase64Encoded":{'S': str(event['isBase64Encoded'])},
            "queryStringParameters":{'S': json.dumps(event['queryStringParameters'])},
            "multiValueQueryStringParameters":{'S': json.dumps(event['multiValueQueryStringParameters'])},
            "email":{'S': email},
            "name":{'S': name},
            'cost':{'S': str(float(prices["{0}{1}".format(event['httpMethod'],event['path'])]))}
        },
        TableName='OpenAPI-table',
    )
    
    # Queue message to the caller sqs
    sqs = boto3.client('sqs')
    response = sqs.send_message(
        QueueUrl='https://sqs.us-east-1.amazonaws.com/9999999999/OpenAPI-queue',
        MessageBody=json.dumps(
            {
                'httpMethod':event['httpMethod'],
                'path':event['path'],
                'resource':event['path'],
                "body": event['body'],
                "isBase64Encoded": event['isBase64Encoded'],
                "queryStringParameters": event['queryStringParameters'],
                "multiValueQueryStringParameters": event['multiValueQueryStringParameters'],
                "email": email,
                "name": name,
            })
        )
    return {
        'headers' : headers['headers'],
        'statusCode': 200,
        'body': json.dumps({'message':"Your request is queued",'message_id':response['MessageId']})
    }
def api_prices():
    dynamodb = boto3.resource('dynamodb')
    table_info = dynamodb.Table('Open-API-info')
    return table_info.scan()
def collapse_prices(prices):
    return {"{0}{1}".format(price['method'],price['path']):price['price'] for price in prices}

  1. Backend and business enablement Finally to allow the business to keep track on their API behavior With AWS Glue + AWS Athena + AWS Quicksight would allow the customer to create custom BI portals to keep an eye on their revenue Also thanks to the possibility to query DyanmoDB directly with Athena Federated queries for DynamoDB(Github, SAR) Also would be a good idea to use QuickSight Spice to avoid price increments querying AWS DynamoDB and only importing the data to QuickSight once BI cycle is defined

AWS
answered 2 years ago
1

Hi Kaushik,

We had the same problem with API Monetization not being out of the box with the Amazon API Gateway. So we built a solution for this. You can find it on the AWS Marketplace: https://aws.amazon.com/marketplace/pp/prodview-yw66auwcmnmt4

With this solution, you don't need to write any code.

Kind regards,

Allan.

answered 10 months ago
1
AWS
answered 2 years ago
1

The AWS SaaS Marketplace facilitates the process of monetizing APIs because to implement monetization you need mechanisms for procurement, metering, and billing, all of them aligned to your business model. If you do not want to use the AWS Marketplace, AWS Data Exchange, or any other 3rd-party API Monetization Services, then you are going to build it yourself, what is not technically complex, but it is a lot of work. A quick search on the internet is going to show you some 3rd-party API Monetization providers. Also don't refrain from contacting your AWS representative, or the AWS Partner Team to recommend you some partners' solutions.

AWS
Fabian
answered 2 years ago
0

Hey Kaushik - Check out this blog post over Data Exchange for APIs (Released 2 days ago): https://aws.amazon.com/blogs/aws/data-exchange-for-apis-find-subscribe-use-third-party-apis-consistent-authentication/

This makes it simpler for your end users to use the APIs you create, have consistent access, and take advantage of AWS native authentication

Edit: Saw Pradeep's answer after posting mine, the blog I linked has a quick example of how you'd subscribe to a DataExchange API

AWS
answered 2 years ago
0

Hello Kaushik, let us know if any of the answers provides solves your question. If so, please remember to click the "Accept" button for the best answer to let the community know that your question is resolved. This helps everyone. Thank you in advance.

profile picture
SUPPORT ENGINEER
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions