# Authenticating an AWS Lambda against a protected API

**URL:** <https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [February 6, 2023, 4:00pm UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806 "2023-02-06T16:00:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaked.hadas](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shaked.hadas/32/44380_2.png) [@shaked.hadas](https://community.auth0.com/u/shaked.hadas)\
**Post date:** [February 6, 2023, 4:00pm UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806/1 "2023-02-06T16:00:59Z")

</div>

Hi  
I’ve encountered a problem and would love an assistant,  
I’m using auth0 to manage authentications between a react app (SPA application in auth0) and an express backend, also, i need to access the same express backend from a lambda function.

I’ve used M2M authentication to generate access token in the lambda function, this lambda is ran few thousand times few times a month, so i did used my quota pretty quickly.

Is M2M auth is the right way to go in my case? or is there a better way?  
Is there any way to reduce costs in this case?

Thanks for the help

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [February 6, 2023, 10:04pm UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806/3 "2023-02-06T22:04:11Z")

</div>

Hi @shaked.hadas,

Welcome to the Auth0 Community!

Yes, M2M would be the right approach here. You should find some way to cache the token.

It looks like lambda has a caching extension: [Caching data and configuration settings with AWS Lambda extensions | AWS Compute Blog](https://aws.amazon.com/blogs/compute/caching-data-and-configuration-settings-with-aws-lambda-extensions/)

---

<div class="post-metadata">

**Author:** ![shaked.hadas](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shaked.hadas/32/44380_2.png) [@shaked.hadas](https://community.auth0.com/u/shaked.hadas)\
**Post date:** [February 7, 2023, 8:29am UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806/4 "2023-02-07T08:29:34Z")

</div>

Thanks for your help! i will look into it

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [February 7, 2023, 1:53pm UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806/5 "2023-02-07T13:53:22Z")

</div>

Let us know if you have any questions.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 21, 2023, 1:54pm UTC](https://community.auth0.com/t/authenticating-an-aws-lambda-against-a-protected-api/99806/6 "2023-02-21T13:54:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
