You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/2021-12-15-run-lambda-local/index.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,11 @@ _This post explains how to run and debug AWS Lambda's locally without mocking an
37
37
38
38
## The problem
39
39
40
-
Imagine you are building an AWS serverless function. As a good developer you have designed and written your code with paradigms like clean code, TDD. Your code is clean, maintainable and well (unit) tested. But at the moment you deploying your function to the cloud, it does not work as you have expected. Would it not be great if you can locally run, debug and iterate fast. And when deploying to the cloud be 100% certain that your lambda will work smooth.
40
+
Imagine you are building an AWS serverless function. As a good developer you have designed and written your code with paradigms like clean code and TDD. Your code is clean, maintainable and well (unit) tested. But the moment you deploy your function to the cloud, it does not work as you have expected. Would it not be great if you can locally run, debug and iterate fast. And when deploying to the cloud be 100% certain that your lambda will work smooth?
41
41
42
-
So what is the problem. The real world is not so nicely isolated as your test environment for unit testing. There are no mocks, stubs, the environment could be different, the function is invoked differently and IAM permissions are applied. Of course, this is the difference mostly between a unit test and integration test environment.
42
+
So what is the problem? The real world is not so nicely isolated as your test environment for unit testing. There are no mocks or stubs. The environment could be different. The function is invoked differently. And IAM permissions are applied once running in the cloud. Of course, this is the difference mostly between a unit test and integration test environment.
43
43
44
-
Time to out how close can we get to behaviour in the real world, aka cloud while running as much locally.
44
+
Time to find out how close can we get to behavior in the real world, aka cloud while running as much locally.
45
45
46
46
## Tools
47
47
@@ -57,7 +57,7 @@ For this post we use the following tools.
57
57
58
58
## A simple Lambda
59
59
60
-
Let's first build a simple Lambda. We use TypeScript as language for the Lambda which requires a Node runtime environment for excution. This add an extra step between writing the code and running, we need to compile the TypeScript code to JavaScript.
60
+
Let's first build a simple Lambda. We use TypeScript as language for the Lambda which requires a Node runtime environment for execution. This add an extra step between writing the code and running, we need to compile the TypeScript code to JavaScript.
61
61
62
62
We write a [simple program](https://github.com/npalm/aws-lambda-run-local/blob/main/lambda/src/lambda.ts) that sends a message to a SQS queue, Amazon's Simple Queue Service. Actually it does not matter which AWS services we use. We only need integration points to the cloud, so we are also depending on the cloud services for local excution. For simplicity we limit ourselves to only one.
63
63
@@ -67,13 +67,13 @@ Our tiny program will read the SQS queue url and a message from the environment.
@@ -126,7 +126,7 @@ The Lambda function above requires in terms of AWS the following resources.
126
126
-[A SQS queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html), the queue to which we publish message. Since the goal is to run the Lambda as realistic as possible, without any mocking, we need an actual SQS queue.
127
127
-[An execution role](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html), this is the role that defines which resources the Lambda can access. The Lambda needs to send messages to SQS. We also going to use this role locally.
128
128
129
-
Today we have dozen ways to create cloud resources, manual via the web console, [AWS CloudFormation](https://aws.amazon.com/cloudformation/), [Terraform](https://www.terraform.io/), [AWS CDK](https://aws.amazon.com/cdk/), [Pulumi](https://www.pulumi.com/product/), [Serverless Framework](https://www.serverless.com/), e.g. Here we will use Terraform which is an IaC eco-system with no extra tooling to streamline Serverless development. When developing only a serverless application the SAM Framework, CDK or the Serverless Framework may seem a more logical choice. But using Terraform shows us how we can mix and match if we cannot chose every component.
129
+
Today we have dozen of ways to create cloud resources, manually via the web console, [AWS CloudFormation](https://aws.amazon.com/cloudformation/), [Terraform](https://www.terraform.io/), [AWS CDK](https://aws.amazon.com/cdk/), [Pulumi](https://www.pulumi.com/product/), [Serverless Framework](https://www.serverless.com/), e.g. Here we will use Terraform which is an IaC eco-system with no extra tooling to streamline Serverless development. When developing only a serverless application the SAM Framework, CDK or the Serverless Framework may seem a more logical choice. But using Terraform shows us how we can mix and match if we cannot chose every component.
130
130
131
131
Time to create the cloud resources with Terraform. This setup assumes you have an admin role. Clone the [repo](https://github.com/npalm/aws-lambda-run-local/tree/main/terraform) and cd in the Terraform directory to create the resources.
0 commit comments