Test, Debug, and Observe
Now let’s test the complete workflow. Upload a file, watch the function run, and verify the email is sent.
Testing Workflow
Here’s how to test everything:
Step 1: Upload a test file
# Create a test file
echo "This is a test file" > test-document.txt
# Upload to S3
aws s3 cp test-document.txt s3://my-notifications-bucket-2025/
# Verify upload
aws s3 ls s3://my-notifications-bucket-2025/ # Create a test file
echo "This is a test file" > test-document.txt
# Upload to Blob Storage
az storage blob upload \
--account-name mynotifications2025 \
--container-name uploads \
--name test-document.txt \
--file test-document.txt \
--auth-mode login
# Verify upload
az storage blob list \
--account-name mynotifications2025 \
--container-name uploads \
--auth-mode login # Create a test file
echo "This is a test file" > test-document.txt
# Upload to Cloud Storage
gsutil cp test-document.txt gs://my-notifications-bucket-2025/
# Verify upload
gsutil ls gs://my-notifications-bucket-2025/ Step 2: Check function logs
The function should run automatically. Check the logs:
# View recent logs
aws logs tail /aws/lambda/notify-on-upload --follow
# Or in CloudWatch Console:
# 1. Go to CloudWatch → Log groups
# 2. Find /aws/lambda/notify-on-upload
# 3. Click latest log stream
# 4. View log entries In Azure Portal:
1. Go to your Function App
2. Click "Functions" → your function
3. Click "Monitor" tab
4. View "Invocation log" for recent executions
5. Click on an execution to see details
Or use Azure CLI:
az functionapp log tail --name your-function-app --resource-group your-rg # View recent logs
gcloud functions logs read notify-on-upload --limit 20
# Or in Cloud Console:
# 1. Go to Cloud Functions
# 2. Click your function
# 3. Click "Logs" tab
# 4. View recent executions Step 3: Verify email received
- Check your recipient email inbox
- Look for email with subject “New file uploaded: test-document.txt”
- Verify email content includes file details
What to Look For in Logs
Successful execution:
Event received: {...}
File uploaded: test-document.txt in bucket my-notifications-bucket-2025
Message prepared: New file uploaded: test-document.txt
Email sent successfully
Notification sent for: test-document.txt
Error indicators:
ERROR: Email error: ...
ERROR: Missing environment variable: SENDGRID_API_KEY
ERROR: Permission denied
Common Errors and Solutions
Error: Function didn’t run
Symptoms:
- No logs appear
- File uploaded but nothing happens
Possible causes:
- Trigger not configured
- Function in wrong region
- Missing permissions
Solutions:
- Verify trigger is enabled in console
- Check function and bucket are in same region
- Review IAM permissions
- Check trigger configuration
Error: Permission denied
Symptoms:
- Function runs but fails with permission error
- “Access denied” in logs
Possible causes:
- Function lacks permission to access storage
- Email service API key invalid
- Missing IAM role permissions
Solutions:
- Check function execution role has storage read permission
- Verify email service API key is correct
- Review IAM policies
Error: Email sending failed
Symptoms:
- Function runs but email not received
- “Email error” in logs
Possible causes:
- Invalid API key
- Sender email not verified
- Rate limit exceeded
- Invalid recipient email
Solutions:
- Verify API key in environment variables
- Verify sender email in email service dashboard
- Check rate limits
- Verify recipient email address
Error: Missing environment variable
Symptoms:
- “undefined” or “null” errors
- “Missing environment variable” in logs
Possible causes:
- Environment variable not set
- Wrong variable name
- Variable not saved
Solutions:
- Check environment variables in function configuration
- Verify variable names match code
- Redeploy function after setting variables
Debugging Decision Tree
Use this flow to debug issues:
Did the function run?
├─ No → Check trigger configuration
│ ├─ Is trigger enabled?
│ ├─ Are function and bucket in same region?
│ └─ Are permissions correct?
│
└─ Yes → Are there errors in logs?
├─ Yes → Check error type
│ ├─ Permission error → Check IAM roles
│ ├─ Email error → Check API key and email service
│ └─ Missing variable → Check environment variables
│
└─ No → Did email arrive?
├─ No → Check email service logs
└─ Yes → Success! ✅
Common Error Messages
| Error Message | Usually Means | Solution |
|---|---|---|
AccessDenied | Permission issue | Check IAM roles and policies |
InvalidApiKey | Wrong API key | Verify environment variable |
Email not verified | Sender email not verified | Verify email in service dashboard |
Function timeout | Function took too long | Increase timeout or optimize code |
ResourceNotFoundException | Function or bucket not found | Verify names and regions |
Monitoring Best Practices
Set up alerts:
- Function errors
- Email delivery failures
- High error rates
Track metrics:
- Function invocations
- Execution duration
- Error rates
- Email delivery rates
Regular checks:
- Review logs weekly
- Test workflow monthly
- Monitor costs
Testing Checklist
Before considering the system complete:
- File upload works - Can upload files to bucket
- Function triggers - Function runs when file uploaded
- Logs show execution - Can see function logs
- Email sent - Email arrives in inbox
- Email content correct - File details are accurate
- Error handling works - Errors are logged properly
- Multiple files work - System handles multiple uploads
What’s Next?
In the final page, we’ll cover security best practices, understand costs, and learn how to clean up resources when you’re done.