Testing Lambda Function #1

Tổng quan

In this step, you will test the UploadInvoiceFileFunction Lambda Function by uploading a sample invoice file to the S3 bucket. The purpose of this test is to verify the entire processing workflow, from file upload to S3, data extraction with Textract, analysis with Bedrock, and storage in DynamoDB.


Prerequisites

Before testing the Lambda function, prepare a sample invoice file to upload. Please download the following file:

🔧 Note: If you use a different invoice file, rename it to demo_invoice.png before uploading to the uploads/ folder in S3.


Step 1: Upload Invoice File to S3

  1. Go to Amazon S3 Console.

Amazon S3 Console

  1. Open the bucket named: invoice-upload-s3-bucket.

Access S3 Bucket

  1. Open the uploads/ folder.

Open Folder

  1. Click Upload.

Click Upload

  1. Click Add files.

Click Add Files

  1. Choose the file: demo_invoice.png.

Choose File

  1. Click Upload to upload the file.

Upload file to S3

  1. Check the file after upload.

Check file


Step 2: Create Test Event in Lambda Console

  1. Open AWS Lambda Console.

AWS Lambda Console

  1. Navigate to the UploadInvoiceFileFunction function.

  2. Click the Test tab to create a new Test Event.

  3. Event name: TestUploadInvoice.

Test event

  1. Paste the following JSON content into the event section:
{
    "Records": [
        {
            "eventVersion": "2.1",
            "eventSource": "aws:s3",
            "awsRegion": "us-east-1",
            "eventTime": "2025-07-31T12:00:00.000Z",
            "eventName": "ObjectCreated:Put",
            "s3": {
                "bucket": {
                    "name": "invoice-upload-s3-bucket"
                },
                "object": {
                    "key": "uploads/demo_invoice.png"
                }
            }
        }
    ]
}

Paste JSON

  1. Click Save.

Save


Step 3: Run the Test

  1. After creating the Test Event, click the Test button to run it.

Test event

  1. Observe the Execution results displayed after the run:

    • If successful, you will see: Status: succeeded along with log output.

Execution function

Step 4: View Detailed Logs in CloudWatch

  1. In Lambda Console, select the Monitor tab.

Tab Monitor

  1. Click View CloudWatch logs.

View CloudWatch logs

  1. Open the latest log stream.

View CloudWatch logs

  1. Review the logs.

View CloudWatch logs


Step 5: Check Data in DynamoDB

  1. Go to the AWS DynamoDB Console.

AWS DynamoDB Console

  1. Open the InvoiceData table.

InvoiceData

  1. Click Explore table items.

Explore table items

  1. Search for the record with InvoiceId corresponding to demo_invoice.png to confirm it was saved.

Explore table items

⚠️ Warning: Ensure all resources (Lambda, S3, DynamoDB, Textract, and Bedrock) are in the same region: N. Virginia (us-east-1) to ensure proper system synchronization.