Skip to main content

TableListLambda Function

Quick Reference

  • Function Name: payment3-table-list-${BRANCH}
  • Handler: index.lambda_handler
  • Runtime: Python 3.12
  • Trigger: API Gateway (GET /tables)
  • Timeout: 60 seconds (default)
  • Template.yaml: Lines 1506-1542

Function Overview

The TableListLambda function is a simple utility function that returns the names of DynamoDB tables used by the payment system. It provides a convenient way to resolve table names at runtime without hardcoding them. This function is implemented as an inline Lambda function (code embedded in template.yaml).

Entry Point

File: Inline code in template.yaml
Handler: index.lambda_handler

def lambda_handler(event, context):
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps({
'CreditCardCallbackTable': os.environ['CreditCardCallbackTable'],
'QRCallbackRecordTable': os.environ['QRCallbackRecordTable'],
'CardPaymentRecordTable': os.environ['CardPaymentRecordTable'],
'CreditCardNotifyTable': os.environ['CreditCardNotifyTable'],
'QRNotifyTable': os.environ['QRNotifyTable']
})
}

Event Structure

API Gateway Event

Path: GET /tables
Auth: Cognito (via MainApi)

Request: No body required

Response (Success):

{
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{
\"CreditCardCallbackTable\": \"payment3-credit-card-callback-dev\",
\"QRCallbackRecordTable\": \"payment3-qr-callback-record-dev\",
\"CardPaymentRecordTable\": \"payment3-card-payment-record-dev\",
\"CreditCardNotifyTable\": \"payment3-credit-card-notify-dev\",
\"QRNotifyTable\": \"payment3-qr-notify-dev\"
}"
}

Environment Variables

The function uses environment variables set from CloudFormation template references:

  • CreditCardCallbackTable: !Ref CreditCardCallbackTable
  • QRCallbackRecordTable: !Ref QRCallbackRecordTable
  • CardPaymentRecordTable: !Ref CardPaymentRecordTable
  • CreditCardNotifyTable: !Ref CreditCardNotifyTable
  • QRNotifyTable: !Ref QRNotifyTable

Process Flow

  1. Receive API Request: Lambda receives GET request to /tables
  2. Read Environment Variables: Extract table names from environment variables
  3. Build Response: Create JSON response with table names
  4. Return Response: Return HTTP 200 with JSON body

IAM Policies

Required Permissions:

  • AWSLambdaBasicExecutionRole: Basic Lambda execution permissions

Use Cases

  • Table Name Resolution: Clients can query this endpoint to get current table names
  • Dynamic Configuration: Applications can dynamically discover table names
  • Debugging: Useful for verifying table names in different environments
  • Documentation: Provides a programmatic way to list available tables

The function returns names for these DynamoDB tables:

  1. CreditCardCallbackTable: Stores credit card callback records
  2. QRCallbackRecordTable: Stores QR payment callback records
  3. CardPaymentRecordTable: Stores card payment records
  4. CreditCardNotifyTable: Stores credit card notification records
  5. QRNotifyTable: Stores QR notification records

Notes

  • This is an inline Lambda function (code embedded in template.yaml)
  • No external dependencies required
  • Simple utility function for table name resolution
  • Returns table names for the current branch/environment
  • Table names include branch suffix (e.g., -dev, -master)