Making a phone app using API Gateway and Lambda functions. Most of my app lives in a VPC. However I need to add a function to delete a user account from Cognito (per app store rules).
As I understand it, I can’t call the Cognito API from my VPC unless I have a NAT gateway. A NAT gateway is going to be at least $400 a year, for a non-critical function that will seldom happen.
Soooooo… My plan is to create a “delete Cognito user” lambda function outside the VPC, and then use an SQS queue to message from my main “delete user” lambda (which handles all the database deletion) to the function outside the VPC. This way it should cost me nothing.
Is there any issue with that? Yes I have a function outside the VPC but the only data it has/gets is a user ID and the only thing it can do is delete it, and the only way it’s triggered is from the SQS queue.
Yes, that would be a perfectly fine way to architect around that. Ideally only functions that actually need access to private resources should be attached to a VPC anyway
Thanks! Most of my API functions need access to the RDS database, but that’s good that my “batch-type” functions don’t need to be in the VPC, and those are really the ones that need to access the internet.
Thanks. That’s true. For me, I’m pretty comfortable with SQS and it seems like a better chance of catching a problem as the message will end up in the DLQ if it doesn’t get processes.
Well I have the lambda that does all the database cleanup to eliminate the user, and that has to be in the VPC because it accesses the RDS database. But correct, that function will call my “delete cognito user” function outside the VPC, and it will do the last bit, which is actually deleting the user from the cognito user pool.
Since it’s not a critical function don’t forget you can use a NAT instance which will cost a fraction of a NAT gateway and save yourself the complicated (relatively..) but valid solution you describe.
Be aware that lambda has async polling and will result in a lot of sqs polling. Not a big deal, but just be aware you’ll hit about 500k polls in a month