Lambda Functions

Overview

Lexi backend uses 23 Lambda functions organized into modules:

ModuleNumber of FunctionsPurpose
Onboarding1Complete new user information
Admin5Manage users and scenarios
Profile2Manage user profiles
Flashcard10Manage flashcards (CRUD, review, export/import, statistics)
Vocabulary2Translate vocabulary and sentences
Speaking2Speaking practice (WebSocket + Session management)
Scenarios1List public scenarios

Check Lambda Functions

# List all Lambda functions
aws lambda list-functions \
  --region <REGION> \
  --output table

# List only Lexi functions
aws lambda list-functions \
  --region <REGION> \
  --query 'Functions[?starts_with(FunctionName, `lexi-be`)].FunctionName' \
  --output table

Expected result: 20+ functions

Get Specific Function Information

# Get function information
aws lambda get-function \
  --function-name <FUNCTION_NAME> \
  --region <REGION>

# Or get only configuration
aws lambda get-function-configuration \
  --function-name <FUNCTION_NAME> \
  --region <REGION>

Result will include:

  • FunctionName
  • Runtime (python3.12)
  • Handler path
  • MemorySize, Timeout
  • Environment variables
  • IAM role

View Lambda Logs

# View function logs
aws logs tail /aws/lambda/<FUNCTION_NAME> \
  --region <REGION> \
  --follow

# Or list log groups
aws logs describe-log-groups \
  --log-group-name-prefix /aws/lambda/lexi-be \
  --region <REGION>

Invoke Lambda Function

# Invoke function directly
aws lambda invoke \
  --function-name <FUNCTION_NAME> \
  --region <REGION> \
  --payload '{}' \
  response.json

# View result
cat response.json

Update Lambda Function

# Update code
aws lambda update-function-code \
  --function-name <FUNCTION_NAME> \
  --zip-file fileb://function.zip \
  --region <REGION>

# Update configuration
aws lambda update-function-configuration \
  --function-name <FUNCTION_NAME> \
  --memory-size 256 \
  --timeout 30 \
  --region <REGION>

# Update environment variables
aws lambda update-function-configuration \
  --function-name <FUNCTION_NAME> \
  --environment Variables={KEY=VALUE} \
  --region <REGION>

Monitor Lambda Metrics

# View Lambda invocations
aws cloudwatch get-metric-statistics \
  --namespace AWS/Lambda \
  --metric-name Invocations \
  --start-time 2026-05-01T00:00:00Z \
  --end-time 2026-05-02T00:00:00Z \
  --period 3600 \
  --statistics Sum \
  --region <REGION>

# View Lambda errors
aws cloudwatch get-metric-statistics \
  --namespace AWS/Lambda \
  --metric-name Errors \
  --start-time 2026-05-01T00:00:00Z \
  --end-time 2026-05-02T00:00:00Z \
  --period 3600 \
  --statistics Sum \
  --region <REGION>

# View Lambda duration
aws cloudwatch get-metric-statistics \
  --namespace AWS/Lambda \
  --metric-name Duration \
  --start-time 2026-05-01T00:00:00Z \
  --end-time 2026-05-02T00:00:00Z \
  --period 3600 \
  --statistics Average,Maximum \
  --region <REGION>

Troubleshooting

Issue: Lambda function error

# View logs
aws logs tail /aws/lambda/<FUNCTION_NAME> \
  --region <REGION> \
  --follow

# Check IAM role
aws iam get-role-policy \
  --role-name <ROLE_NAME> \
  --policy-name <POLICY_NAME>

Issue: Lambda timeout

# Increase timeout
aws lambda update-function-configuration \
  --function-name <FUNCTION_NAME> \
  --timeout 60 \
  --region <REGION>

Issue: Lambda out of memory

# Increase memory
aws lambda update-function-configuration \
  --function-name <FUNCTION_NAME> \
  --memory-size 512 \
  --region <REGION>

Next Steps

Continue to DynamoDB to learn how to manage the database.

Checklist

  • Lambda functions deployed
  • Function logs accessible
  • Metrics visible in CloudWatch
  • Invocation test successful
  • IAM permissions configured correctly