Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Step 1: Create a Lambda Function

Focus mode
Step 1: Create a Lambda Function - Amazon Lex V1

End of support notice: On September 15, 2025, AWS will discontinue support for Amazon Lex V1. After September 15, 2025, you will no longer be able to access the Amazon Lex V1 console or Amazon Lex V1 resources. If you are using Amazon Lex V2, refer to the Amazon Lex V2 guide instead. .

End of support notice: On September 15, 2025, AWS will discontinue support for Amazon Lex V1. After September 15, 2025, you will no longer be able to access the Amazon Lex V1 console or Amazon Lex V1 resources. If you are using Amazon Lex V2, refer to the Amazon Lex V2 guide instead. .

First, create a Lambda function which fulfills a pizza order. You specify this function in your Amazon Lex bot, which you create in the next section.

To create a Lambda function

  1. Sign in to the AWS Management Console and open the AWS Lambda console at https://console.aws.amazon.com/lambda/.

  2. Choose Create function.

  3. On the Create function page, choose Author from scratch.

    Because you are using custom code provided to you in this exercise to create a Lambda function, you choose author the function from scratch.

    Do the following:

    1. Type the name (PizzaOrderProcessor).

    2. For the Runtime, choose the latest version of Node.js.

    3. For the Role, choose Create new role from template(s).

    4. Enter a new role name (PizzaOrderProcessorRole).

    5. Choose Create function.

  4. On the function page, do the following:

    In the Function code section, choose Edit code inline, and then copy the following Node.js function code and paste it in the window.

    'use strict'; // Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes") function close(sessionAttributes, fulfillmentState, message) { return { sessionAttributes, dialogAction: { type: 'Close', fulfillmentState, message, }, }; } // --------------- Events ----------------------- function dispatch(intentRequest, callback) { console.log(`request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.name}`); const sessionAttributes = intentRequest.sessionAttributes; const slots = intentRequest.currentIntent.slots; const crust = slots.crust; const size = slots.size; const pizzaKind = slots.pizzaKind; callback(close(sessionAttributes, 'Fulfilled', {'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${pizzaKind} pizza on ${crust} crust`})); } // --------------- Main handler ----------------------- // Route the incoming request based on intent. // The JSON body of the request is provided in the event slot. export const handler = (event, context, callback) => { try { dispatch(event, (response) => { callback(null, response); }); } catch (err) { callback(err); } };
  5. Choose Save.

Test the Lambda Function Using Sample Event Data

In the console, test the Lambda function by using sample event data to manually invoke it.

To test the Lambda function:
  1. Sign in to the AWS Management Console and open the AWS Lambda console at https://console.aws.amazon.com/lambda/.

  2. On the Lambda function page, choose the Lambda function (PizzaOrderProcessor).

  3. On the function page, in the list of test events, choose Configure test events.

  4. On the Configure test event page, do the following:

    1. Choose Create new test event.

    2. In the Event name field, enter a name for the event (PizzaOrderProcessorTest).

    3. Copy the following Amazon Lex event into the window.

      { "messageVersion": "1.0", "invocationSource": "FulfillmentCodeHook", "userId": "user-1", "sessionAttributes": {}, "bot": { "name": "PizzaOrderingApp", "alias": "$LATEST", "version": "$LATEST" }, "outputDialogMode": "Text", "currentIntent": { "name": "OrderPizza", "slots": { "size": "large", "pizzaKind": "meat", "crust": "thin" }, "confirmationStatus": "None" } }
  5. Choose Create.

AWS Lambda creates the test and you go back to the function page. Choose Test and Lambda runs your Lambda function.

In the result box, choose Details. The console displays the following output in the Execution result pane.

{ "sessionAttributes": {}, "dialogAction": { "type": "Close", "fulfillmentState": "Fulfilled", "message": { "contentType": "PlainText", "content": "Okay, I have ordered your large meat pizza on thin crust." } }

Next Step

Step 2: Create a Bot

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.