AWS Lambda

Configuring Lambda

Create a Pull Event SQS Function using Blueprint

In this tutorial, you’ll learn how to set up an AWS Lambda function that polls an SQS queue and processes incoming messages. We’ll use the built-in SQS blueprint, configure permissions, and verify the end-to-end flow.

Prerequisites

  • An existing SQS queue named KodeKloudDemoQueue
  • IAM permissions to create Lambda functions and roles
  • Basic familiarity with AWS Lambda and Amazon SQS

1. Navigate to the AWS Lambda Console

  1. Open the AWS Management Console
  2. In the search bar, type Lambda and select AWS Lambda

AWS Management Console search for "lambda" in dark mode, highlighting AWS services including AWS Lambda.

2. Create a New Function from a Blueprint

  1. Click Create function
  2. Select the Blueprint tab
  3. Enter SQS in the filter box and choose the sqs-invoke-lambda blueprint
  4. Click Configure

Lambda console "Create function" screen showing blueprint selection, with an SQS processing blueprint highlighted.

Function Settings

  • Function name: KodeKloudSQSDemo
  • Execution role: Keep Create a new role from AWS policy templates

Lambda function configuration screen with function name "KodeKloudSQSdemo" and execution role options.

Scroll to Policy templates and confirm Amazon SQS Poller (or Amazon SQS Pull event permissions) is checked. Lambda requires these permissions to read and delete messages from your queue.

Lambda execution role creation interface with Amazon SQS poller permissions policy template selected.

  • Role name: demo-lambda-sqs-role

3. Configure the SQS Trigger

Under Configure triggers, pick your KodeKloudDemoQueue queue.

ParameterValueDescription
Batch size1Number of messages retrieved per Lambda invocation
Batch window1 sMaximum wait time before invocation

Lambda SQS trigger configuration screen showing batch size and batch window options.

Note

You can expand Additional settings to apply JSON filters or configure batch-item failure reporting. For this demo, we’ll skip filters.

Lambda batch settings page showing batch size, window, and additional settings like filters.

4. Review and Deploy the Handler Code

The blueprint generates this sample Node.js handler:

console.log('Loading function');

exports.handler = async (event) => {
  for (const { messageId, body } of event.Records) {
    console.log('SQS message %s: %j', messageId, body);
  }
  return `Successfully processed ${event.Records.length} messages.`;
};

Click Create function. AWS will provision your Lambda and attach the SQS trigger automatically.

Lambda console showing the newly created function "KodeKloudSQSdemo" with an SQS trigger.

5. Send a Test Message to SQS

  1. In the AWS Console search bar, select Simple Queue Service
  2. Open KodeKloudDemoQueue
  3. Click Send and receive messages, enter KodeKloud Demo Test as the body, and hit Send message

Amazon SQS console for the queue "KodeKloudDemoQueue" with queue details and options to send messages.

SQS interface for composing and sending a message, with message body "KodeKloud Demo Test".

6. Verify Lambda Invocation in CloudWatch

  1. Return to the Lambda console for KodeKloudSQSDemo
  2. Select the Monitor tab
  3. Check Invocations and Errors in the CloudWatch metrics

Lambda monitoring dashboard showing CloudWatch metrics for invocations, duration, and errors.

Click View logs in CloudWatch to inspect the log stream. You should see entries for your loaded function and the test message body.

CloudWatch log events showing Lambda execution logs, including the received SQS message.

Next Steps

You’ve successfully:

  • Created a Lambda function from the SQS blueprint
  • Configured IAM roles and pull permissions
  • Deployed an SQS trigger and processed a test message

Extend this workflow by integrating with SNS, writing to DynamoDB, or chaining additional Lambda functions.


Watch Video

Watch video content

Previous
Create a Canary Function using Blueprint