# SQS as a NAT Gateway workaround

**URL:** <https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941>\
**Category:** AWS Networking\
**Tags:** vpc, lambda, sqs, nat-gateway, cognito\
**Created:** [April 15, 2025, 6:24pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941 "2025-04-15T18:24:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 6:24pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/1 "2025-04-15T18:24:22Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![clintkev251](https://awshq.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@clintkev251](https://awshq.com/u/clintkev251)\
**Post date:** [April 15, 2025, 6:30pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/2 "2025-04-15T18:30:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 6:33pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/3 "2025-04-15T18:33:31Z")

</div>

> [@clintkev251](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![zepplenzap](https://awshq.com/letter_avatar_proxy/v4/letter/z/2acd7d/32.png) [@zepplenzap](https://awshq.com/u/zepplenzap)\
**Post date:** [April 15, 2025, 6:36pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/4 "2025-04-15T18:36:23Z")

</div>

You can also just do an asynchronous invoke of your non vpc lambda, if you don’t want to manage the sqs queue yourself.

---

<div class="post-metadata">

**Author:** ![KayeYess](https://awshq.com/letter_avatar_proxy/v4/letter/k/f17d59/32.png) [@KayeYess](https://awshq.com/u/KayeYess)\
**Post date:** [April 15, 2025, 6:40pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/5 "2025-04-15T18:40:06Z")

</div>

No issues.

---

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 6:40pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/6 "2025-04-15T18:40:57Z")

</div>

> [@zepplenzap](#):
>
> You can also just do an asynchronous invoke of your non vpc lambda, if you don’t want to manage the sqs queue yourself.

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.

---

<div class="post-metadata">

**Author:** ![FlinchMaster](https://awshq.com/letter_avatar_proxy/v4/letter/f/b77776/32.png) [@FlinchMaster](https://awshq.com/u/FlinchMaster)\
**Post date:** [April 15, 2025, 6:47pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/7 "2025-04-15T18:47:14Z")

</div>

> [@Beneficial\_Ad\_5485](#):
>
> 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.

Could also just do an async lambda invocation with a DLQ setup on it. Skips the whole need for a queue consumer event source on the lambda.

---

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 6:48pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/8 "2025-04-15T18:48:22Z")

</div>

> [@FlinchMaster](#):
>
> Could also just do an async lambda invocation with a DLQ setup on it. Skips the whole need for a queue consumer event source on the lambda.

True. Thanks for the tip!

---

<div class="post-metadata">

**Author:** ![FlinchMaster](https://awshq.com/letter_avatar_proxy/v4/letter/f/b77776/32.png) [@FlinchMaster](https://awshq.com/u/FlinchMaster)\
**Post date:** [April 15, 2025, 6:48pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/9 "2025-04-15T18:48:47Z")

</div>

You don’t really need to get a VPC involved here at all, right?

Just create a Lambda outside of your VPC that your app can call and have it call Cognito.deleteUser.

---

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 6:51pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/10 "2025-04-15T18:51:26Z")

</div>

> [@FlinchMaster](#):
>
> You don’t really need to get a VPC involved here at all, right? Just create a Lambda outside of your VPC that your app can call and have it call Cognito.deleteUser.

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.

---

<div class="post-metadata">

**Author:** ![Glebun](https://awshq.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@Glebun](https://awshq.com/u/Glebun)\
**Post date:** [April 15, 2025, 8:43pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/11 "2025-04-15T20:43:44Z")

</div>

> [@Beneficial\_Ad\_5485](#):
>
> 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 …

FYI rds data API doesn’t require a vpc

---

<div class="post-metadata">

**Author:** ![OpportunityIsHere](https://awshq.com/letter_avatar_proxy/v4/letter/o/bbe5ce/32.png) [@OpportunityIsHere](https://awshq.com/u/OpportunityIsHere)\
**Post date:** [April 15, 2025, 8:44pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/12 "2025-04-15T20:44:59Z")

</div>

> [@Beneficial\_Ad\_5485](#):
>
> 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.

Have you looked at data api? That way your lambda uses an http layer to call instead of needing a direct connection.

---

<div class="post-metadata">

**Author:** ![Beneficial\_Ad\_5485](https://awshq.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@Beneficial\_Ad\_5485](https://awshq.com/u/Beneficial_Ad_5485)\
**Post date:** [April 15, 2025, 8:51pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/13 "2025-04-15T20:51:45Z")

</div>

> [@Glebun](#):
>
> FYI rds data API doesn’t require a vpc

Thanks. Only on Aurora though, as far as I know. I’m using RDS MySQL.

---

<div class="post-metadata">

**Author:** ![sfltech](https://awshq.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@sfltech](https://awshq.com/u/sfltech)\
**Post date:** [April 15, 2025, 10:41pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/14 "2025-04-15T22:41:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chemosh\_tz](https://awshq.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@chemosh\_tz](https://awshq.com/u/chemosh_tz)\
**Post date:** [April 15, 2025, 11:01pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/15 "2025-04-15T23:01:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![water\_bottle\_goggles](https://awshq.com/letter_avatar_proxy/v4/letter/w/8e7dd6/32.png) [@water\_bottle\_goggles](https://awshq.com/u/water_bottle_goggles)\
**Post date:** [April 15, 2025, 11:32pm UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/16 "2025-04-15T23:32:14Z")

</div>

> [@chemosh\_tz](#):
>
> 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

cries in pennies

---

<div class="post-metadata">

**Author:** ![SharkbaitOoHaaHaa](https://awshq.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@SharkbaitOoHaaHaa](https://awshq.com/u/SharkbaitOoHaaHaa)\
**Post date:** [April 16, 2025, 12:11am UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/17 "2025-04-16T00:11:21Z")

</div>

You could also use a VPC endpoint, but that would still cost around $80USD/year.

---

<div class="post-metadata">

**Author:** ![SalemGolemUGOO](https://awshq.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@SalemGolemUGOO](https://awshq.com/u/SalemGolemUGOO)\
**Post date:** [April 16, 2025, 12:23am UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/18 "2025-04-16T00:23:56Z")

</div>

Or just use [https://fck-nat.dev/v1.3.0/](https://fck-nat.dev/v1.3.0/), according to your calculations it would be around 40$

---

<div class="post-metadata">

**Author:** ![chemosh\_tz](https://awshq.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@chemosh\_tz](https://awshq.com/u/chemosh_tz)\
**Post date:** [April 16, 2025, 2:29am UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/19 "2025-04-16T02:29:15Z")

</div>

> [@water\_bottle\_goggles](#):
>
> cries in pennies

No doubt, bit I see complaints about why there’s 600k polls to sqs in a month when they only send a free requests to sqs

---

<div class="post-metadata">

**Author:** ![runitzerotimes](https://awshq.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@runitzerotimes](https://awshq.com/u/runitzerotimes)\
**Post date:** [April 16, 2025, 2:42am UTC](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941/20 "2025-04-16T02:42:11Z")

</div>

Keeping every single thing inside a VPC is overrated.

Cognito isn’t in your VPC. Think about that conceptually for a minute.

[Next page](https://awshq.com/t/sqs-as-a-nat-gateway-workaround/19941.md?page=2)
