Skip to content

Commit 41b4cfa

Browse files
committed
Fix typo's
1 parent 479d963 commit 41b4cfa

File tree

1 file changed

+8
-8
lines changed
  • content/posts/2021-12-15-run-lambda-local

1 file changed

+8
-8
lines changed

content/posts/2021-12-15-run-lambda-local/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ _This post explains how to run and debug AWS Lambda's locally without mocking an
3737

3838
## The problem
3939

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?
4141

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.
4343

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.
4545

4646
## Tools
4747

@@ -57,7 +57,7 @@ For this post we use the following tools.
5757

5858
## A simple Lambda
5959

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.
6161

6262
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.
6363

@@ -67,13 +67,13 @@ Our tiny program will read the SQS queue url and a message from the environment.
6767
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
6868
import { Context, ScheduledEvent } from "aws-Lambda";
6969

70+
const client = new SQSClient({});
71+
7072
export async function handler(
7173
event: ScheduledEvent,
7274
context: Context
7375
): Promise<void> {
7476

75-
const client = new SQSClient({});
76-
7777
try {
7878

7979
const queueUrl = getEnvVariable("QUEUE_URL");
@@ -126,7 +126,7 @@ The Lambda function above requires in terms of AWS the following resources.
126126
- [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.
127127
- [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.
128128

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.
130130

131131
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.
132132

@@ -241,7 +241,7 @@ region=eu-west-1
241241
role_arn=arn:aws:iam::<ACCOUNT_ID>:role/test/blog-test
242242
```
243243

244-
As alterfnative of setting up a rol you can invoke the STS services to obtain credentials for the Lambda execution role.
244+
As alternative of setting up a role you can invoke the STS services to obtain credentials for the Lambda execution role.
245245

246246
```bash
247247
role=$(aws sts assume-role --role-arn "$role_arn" \

0 commit comments

Comments
 (0)