The Secret of the Second Family
My name is Eleanor, and my husband was named William. We had a happy family—two daughters whom William adored, spoiling them as if they were little princesses. They loved him more than they loved me. I cherished him dearly, and he seemed to feel the same. But lately, I noticed he had grown irritable, sometimes snapping at the girls. His tension mounted, and my heart ached with unease.
I couldn’t fathom what was troubling him. When I asked, he brushed me off:
“Trouble at work, Ellie. Don’t fret over it.”
His words eased my mind a little, but the strain in our home lingered. I resolved to press him further, but just then, the telephone rang. A strange woman’s voice, cold and sharp, spoke:
“Did you know your husband has another family? He has a son named Oliver.”
The line went dead. I stood frozen, unable to believe it. My William—a betray# Node.js AWS Lambda – Steps to get started
—
### Credits:
1. [Quick start guide to AWS Lambda: Part 1](https://medium.com/@anjanava.biswas/quick-start-guide-to-aws-lambda-part-1-7d1a8947a1a4)
2. [Quick start guide to AWS Lambda: Part 2](https://medium.com/@anjanava.biswas/quick-start-guide-to-aws-lambda-part-2-b2111e83f9cf)
3. [Official AWS docs – Getting started with Lambda](https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html)
4. [How to set up a NodeJS app on AWS Lambda](https://medium.com/codebase/how-to-setup-a-nodejs-app-on-aws-lambda-172306410ffe)
5. [Official AWS docs – AWS SDK for Javascript in Node.js (v3)](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html)
6. [Official AWS docs – AWS Lambda with Node.js](https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html)
—
## 1. Getting started with AWS Lambda in Node.js:
1. **Create an AWS account**
– Log in to your AWS account and navigate to the [AWS Lambda Dashboard](https://console.aws.amazon.com/lambda/).
2. **Create a new Lambda function**:
– Click on **Create function**.
– Choose **Author from scratch**.
– Fill in the **Function name** (e.g., `my-node-lambda`).
– Choose **Node.js** as the Runtime.
– Click **Create function**.
3. **Write a basic Lambda function**:
– In the **Code source** editor, replace the default code with a simple Node.js handler:
“`javascript
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify(‘Hello from Lambda!’),
};
return response;
};
“`
– Click **Deploy** to save your changes.
4. **Test the Lambda function**:
– Click on the **Test** tab.
– Enter a name for your test event (e.g., `myTestEvent`).
– Use the default JSON payload or modify it as needed:
“`json
{}
“`
– Click **Save changes**.
– Click **Test** to run the function.
– View the execution results in the **Execution results** section.
5. **Configure the function (optional)**:
– In the **Configuration** tab, you can adjust:
– **General configuration**: Timeout, memory, etc.
– **Permissions**: IAM role for the Lambda function.
– **Environment variables**: Add variables if needed.
– **Tags**: Add metadata tags for easier management.
6. **Invoke the Lambda function via API Gateway (optional)**:
– Navigate to **API Gateway** in the AWS Console.
– Create a new REST API.
– Create a resource and a method (e.g., `GET /hello`).
– Choose **Lambda Function** as the integration type and select your Lambda function.
– Deploy the API and test the endpoint.
—
## 2. Key Concepts:
1. **Lambda Execution Model**:
– Lambda functions are stateless and ephemeral.
– Each invocation runs in an isolated environment.
2. **Cold Starts**:
– The first invocation of a Lambda function may experience latency due to initialization (cold start).
– Subsequent calls (warm starts) are faster.
3. **Triggers**:
– Lambda functions can be triggered by AWS services like S3, DynamoDB, API Gateway, etc.
4. **Logging and Monitoring**:
– Lambda logs are sent to **AWS CloudWatch**.
– Use `console.log` or `console.error` for logging.
5. **Error Handling**:
– Handle errors gracefully in your function to avoid unexpected behavior.
—
## 3. Best Practices:
1. **Keep Functions Small and Focused**:
– Each Lambda function should perform a single task.
2. **Use Environment Variables**:
– Store sensitive data or configuration outside the code.
3. **Optimize Performance**:
– Minimize the use of external libraries to reduce cold start time.
4. **Reuse Connections**:
– Initialize database connections outside the handler to reuse them across invocations.
5. **Set Appropriate Timeouts and Memory**:
– Adjust function timeout and memory settings based on requirements.
—
## 4. Further Reading:
– [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
– [AWS Lambda Best Practices](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
– [Serverless Framework for AWS Lambda](https://www.serverless.com/)