...

/

Lambda Function: Configuration

Lambda Function: Configuration

Learn to set up Lambda functions to work seamlessly with DynamoDB.

We'll cover the following...

We've created the DynamoDB table to store the inventory information. We also have the logic for the Lambda handler. Now, let's add the Lambda function to our serverless.yml.

import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";

export const hello = async (
  event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: "Welcome to the Sweet Factory!",
      input: event,
    }),
  };
};
Project

In the code below, in our hello function (within the functions section), we'll add the ingredientPreparation function declaration with a link to the handler, and we'll add an environment variable with INVENTORY_TABLE :

Press + to interact
functions:
... previous configuration
ingredientPreparation:
handler: handlers/ingredientPreparation.handler
environment:
INVENTORY_TABLE: ${self:resources.Resources.InventoryTable.Properties.TableName}

In the given configuration, we use the environment property to set environment variables for the Lambda function. By using environment variables, we can easily manage and access configuration values within the function without hardcoding them. Hardcoding values is generally not a good idea. This is because it can lead to ...