SaaS catalog integration in API Gateway
Interface your DynamoDB tenant catalog directly from API Gateway
Dave Roberts
Amazon Employee
Published Jan 6, 2025
A catalog for a SaaS control plane capability can be a useful thing.
Your application needs to know about your tenants. What is their status, what service tier do they belong to? A common practice is to use a tenant catalog to hold this information.
Likewise, you may have use for a resource catalog, mapping resources to tenants and vice-versa. A similar story can be seen with entitlements, and billing.
If you're using DynamoDB for your catalog and have an API architectural approach, then you can do a service integration with API Gateway to simplify your architecture. The challenge here is that you need to map the request to DynamoDB and map the response back.
Here's an example of doing this for a tenant catalog. This represents a tenant entity, and this will be our API request:
I'll model this in DynamoDB as:
In CDK, I need to create the integration responses I care about. I leave success (200) separate from error responses because I will extend that to map responses on a case-by-case basis.
I also need the method responses I care about:
Now, I can create an integration to create tenant entries. I have a request template for mapping the JSON received from API Gateway into the correct format for the DynamoDB API. This uses the Velocity Template Language (VTL).
I have introduced a TENANTID# prefix in the primary key because I may need to represent relationships in the same table.
Now, I can add the integration to a method:
Deploy, and you can test in the console using the following JSON:
For reads, we do a similar approach, mapping the request and response. I have created a new integration response which maps the DynamoDB response into more useful JSON.
I'm using a proxy path for the get request, to specify the tenant to retrieve.
To read all tenants, we do a scan and iterate across all the results. Unfortunately, we have a limit of 1000 iterations for a VTL foreach loop. However, that's a problem for future Dave when his successful SaaS product takes off!
If your SaaS control plane uses an API Gateway based architecture, then you can use a direct integration with DynamoDB to interface your control plane catalogs. This means I don't need to a Lambda to perform this function, which means fewer functions to manage!
Hope this has been useful for you, keep looking for out for more Data for SaaS patterns!
Cheers,
Dave
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.