Seeking Help with API Gateway and Lambdas Setup

0
9
Asked By TechieWhiz42 On

I'm currently working on a CloudFormation template that sets up an API Gateway along with AWS Lambdas and DynamoDB tables. Each Lambda primarily handles CRUD operations for various resources like customers, membership applications, polls, and products, including a Stripe webhook that doesn't interact with any tables. I plan to expand this setup with more Lambdas when I build out additional app modules. Before moving on to the next services, I have a few issues I'd like to resolve:

1. The YAML file I'm using for the API specification is quite messy, and while I thought of leveraging FastAPI for better documentation, it would mean creating a separate FastAPI app for each Lambda, leading to multiple endpoints for documentation (e.g., /prod/docs). Wouldn't that complicate things for front-end developers since they would need to know the entities beforehand?
2. I'm looking to set up automated test cases to avoid manual testing, but I'm facing challenges mainly due to the requirements of AWS Cognito. Certain triggers need validation, and Cognito requires a valid email for authentication, after which JWT tokens are essential for accessing the endpoints. I'm unsure how to go about testing these triggers effectively. Should I consider using the Python unittest framework or are there better tools or AWS services to assist?

Additionally, I have some design questions:
1. Is it considered a bad practice to have one Lambda dedicated mainly for CRUD operations per table?
2. How is user role verification typically handled? Currently, roles are stored as fields in a table, and for endpoints requiring admin or member roles, I just retrieve and check the role. I wonder if there's a more standardized AWS solution, like using Cognito with built-in decorators or wrappers for this.

2 Answers

Answered By CodeGuru887 On

Instead of using "/entity/docs", just serve the OpenAPI schema directly. It’s a more standard approach and saves the hassle for frontend developers trying to figure out which endpoint to access. As for testing, consider using disposable email services to automate end-to-end tests. Regarding the Lambda functions, I find managing a single Lambda for everything a bit tricky; it can complicate deployments and make debugging harder. Keeping your Lambdas focused typically makes things easier in the long run. For user roles, just so you know, Cognito actually allows you to set up groups and custom attributes, which are included in the JWT tokens you receive. That can simplify role management!

Answered By LambdaLover101 On

When it comes to documentation, you have two main options. You can manually create the OpenAPI spec as your core reference, which can be defined in your CloudFormation template to set up the routes. Alternatively, you could go with a single Lambda or a couple of them to handle operations more efficiently. Sure, some people swear by having a separate Lambda per function, but that's often not practical—too many functions complicate IAM roles and workflow. It's better to find a balance that works for your development process. By the way, I get your reservations about FastAPI running on Lambdas; they’re designed for more persistent applications, so that could introduce unexpected issues.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.