# What exactly happens when a lambda is invoked locally?

**URL:** <https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683>\
**Category:** Serverless Framework\
**Created:** [September 4, 2018, 2:33pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683 "2018-09-04T14:33:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slatfatf](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@slatfatf](https://forum.serverless.com/u/slatfatf)\
**Post date:** [September 4, 2018, 2:33pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683/1 "2018-09-04T14:33:32Z")

</div>

I’m curious about what’s actually happening when using `sls invoke local`

I’ve noticed that in order to successfully invoke functions locally I have to deploy my service at least once before hand, however the execution environment is local.

I’m hoping someone can explain this behavior / what is actually happening when invoking locally. As a note, I’m accessing DynamoDB in my functions.

Thanks a ton everyone.

---

<div class="post-metadata">

**Author:** ![jeremydaly](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jeremydaly/32/2104_2.png) [@jeremydaly](https://forum.serverless.com/u/jeremydaly)\
**Post date:** [September 5, 2018, 2:28pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683/2 "2018-09-05T14:28:40Z")

</div>

Invoking functions locally with Serverless just provides a wrapper to your functions which loads variables provided by the `serverless.yml` file and sets your IAM permissions using the `profile` you set. So if you create environment variables in your config, Serverless will load those and make them available to the actual handlers that you are running. The reason why _you_ had to deploy first, is because you are using DynamoDB. In order to connect to DynamoDB tables, they must be created first. On your first `deploy` those tables would be created in your AWS account. Then when you run your functions locally, it will actually access those remote DynamoDB tables.

AWS created a downloadable version of DynamoDB that you can run locally: [https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html). It is fine to test your functions against a remote DynamoDB table if you have Internet access. If you want to be able to test the entire app locally (without Internet access), you could use the link above to create your own local DynamoDB instance.

Hope that helps,  
Jeremy

---

<div class="post-metadata">

**Author:** ![slatfatf](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@slatfatf](https://forum.serverless.com/u/slatfatf)\
**Post date:** [September 5, 2018, 3:39pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683/3 "2018-09-05T15:39:15Z")

</div>

Thanks for the detailed response, can you provide an example of how I can specify local lambda invocations to access my local DynamoDB?

---

<div class="post-metadata">

**Author:** ![jeremydaly](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jeremydaly/32/2104_2.png) [@jeremydaly](https://forum.serverless.com/u/jeremydaly)\
**Post date:** [September 5, 2018, 4:46pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683/4 "2018-09-05T16:46:34Z")

</div>

Follow the instructions here: [https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html)

Then you just use the “endpoint” option when using the SDK and specify your local host on the correct port: [https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html)

This SDK above is for node. But each language specific version has the same functionality.

---

<div class="post-metadata">

**Author:** ![teddy-gustiaux](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/teddy-gustiaux/32/2494_2.png) [@teddy-gustiaux](https://forum.serverless.com/u/teddy-gustiaux)\
**Post date:** [September 5, 2018, 7:41pm UTC](https://forum.serverless.com/t/what-exactly-happens-when-a-lambda-is-invoked-locally/5683/5 "2018-09-05T19:41:25Z")

</div>

The response given by @jeremydaly covers it all, but I just wanted to mention the [serverless-dynamodb-local plugin](https://github.com/99xt/serverless-dynamodb-local) (which appears to use the aforementioned downloadable version of DynamoDB provided by AWS).
