Engineering reference: the invoice chaser architecture
Same system, drawn for engineers. Region, service names, resource identifiers, Bedrock model IDs, Lambda inventory, IAM scopes, the SES inbound rule set, EventBridge Scheduler config, the DynamoDB schemas, and the Slack interactive flow. Read alongside the previous six posts; this one’s the build sheet.
Region and account shape
Default region: ap-southeast-1 (Singapore). SES inbound, Bedrock Global cross-Region inference, and EventBridge Scheduler are all in good shape there. A second region for multi-region resilience isn’t worth the extra setup work at SMB volume — the failure mode for an SMB is a reminder that goes out a day late, not a regional outage. One AWS account dedicated to the chaser (separate from your other workloads) keeps the IAM blast radius small and lets a single AWS Budgets alarm cover the whole system.
Topology
Lambda functions
All Lambdas use the arm64 architecture, the smallest memory size that meets latency targets (typically 256 MB), Python 3.14 runtime, and CloudWatch Logs at 7-day retention. Each function has its own least-privilege IAM role. None run inside a VPC.
drive-sync— EventBridge Scheduler target, fires every 15 minutes. Uses the Google Drive API + Sheets API (service-account credentials in Secrets Manager underic/drive/sa) to export the invoice sheet as CSV and write tos3://ic-invoices-source/invoices.csvonly if the sheet has changed since the last sync. Same pattern syncs the rules and voice docs tos3://ic-rules-source/. Memory: 256 MB. Timeout: 30 s.intake-webhook— Lambda Function URL,AuthType: NONEwith a shared-secret check on the request (the secret lives in Secrets Manager underic/webhook/secret). The accounting tool posts each newly issued invoice; the handler maps the tool’s payload to the row shape and either posts a Slack proposal or, for a trusted source, writes the row directly via the Sheets API. Memory: 256 MB. Timeout: 15 s.intake-ses-parser— S3 PUT trigger ons3://ic-raw-mime/. Parses MIME, extracts the PDF attachment, runs Textract viaStartDocumentTextDetection+StartDocumentAnalysis(asynchronously to handle multi-page invoices). On Textract completion (via SNS notification), reads the structured text and calls Bedrock Haiku 4.5 (anthropic.claude-haiku-4-5-20251001-v1:0viaglobal.anthropic.claude-haiku-4-5-20251001-v1:0) to propose an invoice row. Posts the proposal to Slack viachat.postMessagewith Approve/Edit/Discard buttons. For DOCX attachments (Textract doesn’t accept them), falls back topython-docx; XLSX usesopenpyxl. Both packages are stable and widely used in 2026, though their maintenance velocity is light — for an invoice-parsing path that only runs a few times a month, that’s acceptable. If extraction precision becomes a concern, the active community forkpython-docx-ossis a drop-in alternative. Memory: 512 MB. Timeout: 60 s.chaser— EventBridge Scheduler target, daily at 9am local time (the schedule expression runs inTZ_NAMEset to the SMB’s timezone, e.g.Asia/Singapore). Readss3://ic-invoices-source/invoices.csvand the rules and voice docs. For each row, computesdays_past_due, reads chase state fromic-sendsandic-state, decides on a move. Emits one event per row that needs action:ic.first_nudge,ic.follow_up, oric.escalate, with the invoice context as the event payload. Current invoices emit nothing. Reconciles thepaidcolumn againstic-stateand archives chases for newly paid invoices. Memory: 512 MB. Timeout: 60 s. No Bedrock calls.sender— EventBridge rule on the three move events. Resolves contact, checks quiet hours, weekends, and the holiday calendar, formats the reminder from the voice tone template, and ships via SESSendRawEmail. The escalate move resolves to the internal account owner instead of the customer. On a quiet-hours, weekend, or holiday defer, creates a one-off EventBridge Scheduler rule that re-invokessenderat the next available business minute. Writes a row toic-sendsafter a successful send. Memory: 256 MB. Timeout: 30 s.action-handler— Lambda Function URL, public withAuthType: NONE; verifies a Slack signature on Slack-sourced requests and a signed token on pay-link requests. Triggered by Slack interactive button clicks (Pause/Disputed/Write-off) and by customer pay-link clicks. Writes toic-stateandic-audit; on write-off, marks the row closed in the Drive sheet via the Sheets API and archives the chase inic-sends-archive; on a recorded payment, flips state to paid and stops the chase. Memory: 256 MB. Timeout: 15 s.digest— EventBridge Scheduler target, weekly Monday 9am. Readsic-sendsfor the past week and the invoice list; sends a digest message to a configured Slack channel summarizing reminders sent, invoices coming due, and the oldest open balances. No Bedrock; the message is a plain summary table. Memory: 256 MB.summary— EventBridge Scheduler target, monthly on the first Monday at 9am. Reads the past month’sic-sends,ic-state, andic-audit; calls Bedrock Haiku 4.5 to write a one-paragraph cash-flow narrative (total outstanding, oldest invoices, biggest at-risk amounts, written-off total); emails it via SES to the configured stakeholder list. Memory: 512 MB.
Storage
- DynamoDB ·
ic-sends— one row per reminder sent. PK(invoice_id, step_index); attributes:send_date,dispatched_via(email),recipient,move(first_nudge/follow_up/escalate). On-demand. No TTL. - DynamoDB ·
ic-state— one row per invoice. PKinvoice_id; attributes:status(open/paid/paused/disputed/written-off),paused_until(if paused),pause_count,paid_dateandpaid_amount(if paid),by_user. On-demand. - DynamoDB ·
ic-audit— one row per write action of any kind. PK(invoice_id, ts); attributes:action,by_user,before,after. On-demand. No TTL — this is the long-term audit trail. - DynamoDB ·
ic-sends-archive— archived chases after payment or write-off. Same shape asic-sends; PK(invoice_id, chase_id, step_index). On-demand. - S3 ·
ic-invoices-source— mirrored CSV from the Drive invoice sheet. Versioning enabled. Lifecycle to Glacier at 90 days; expiry at 7 years. - S3 ·
ic-rules-source— mirrored rules and voice docs as plain text. Versioning enabled. - S3 ·
ic-raw-mime— raw inbound MIME from forwarded invoices. Lifecycle to Glacier at 30 days; expiry at 7 years. - S3 ·
ic-source-pdfs— the parsed source invoices after the inbound parser handles them, kept for reference if the row links to one.
Bedrock
- Foundation model.
anthropic.claude-haiku-4-5-20251001-v1:0via the Global cross-Region inference profileglobal.anthropic.claude-haiku-4-5-20251001-v1:0. Two callsites:intake-ses-parserfor the inbound invoice parsing, andsummaryfor the monthly cash-flow narrative. Claude Sonnet 4.6 (global.anthropic.claude-sonnet-4-6-20250930-v1:0) is available as a fallback for invoices whose layout the Haiku pass flags as low-confidence, but in practice invoices are structured enough that Haiku handles them. - Embeddings. Not used. The invoice list is structured rows; deterministic lookup beats vector retrieval here. No Knowledge Base, no S3 Vectors.
- Quotas. Default account quotas are more than enough at SMB volume. The chaser itself doesn’t call Bedrock; the parsing lane fires a few times a month at most.
EventBridge Scheduler config
ic-daily-tick—cron(0 9 * * ? *)in the SMB’s timezone. Target:chaserLambda.ic-drive-sync—rate(15 minutes). Target:drive-syncLambda.ic-weekly-digest—cron(0 9 ? * MON *)in TZ. Target:digestLambda.ic-monthly-summary—cron(0 9 ? * 2#1 *)(first Monday at 9am) in TZ. Target:summaryLambda.- One-off rules — created on the fly by
senderwhen a quiet-hours, weekend, or holiday defer is needed. Useat(YYYY-MM-DDTHH:MM:SS)expressions with--action-after-completion DELETEso the rule self-cleans.
SES inbound and outbound
- Set the MX record on a dedicated subdomain (e.g.
invoices.your-company.com) toinbound-smtp.ap-southeast-1.amazonaws.com. - SES inbound rule set
ic-inbound-rules: one rule with recipientinvoices@your-company.com→ spam scan → S3 PUT tos3://ic-raw-mime/<message-id>→ stop. The S3 PUT triggersintake-ses-parser. - SES outbound for the reminder emails: verify a sender identity at
billing@your-company.comwith DKIM and SPF on the parent domain, and set the reply-to to a monitored inbox so customer replies reach a human. Out of sandbox by request.
IAM (least privilege per Lambda)
Each Lambda has its own role with policies scoped to exact ARNs. Sketch:
- chaser role:
s3:GetObjecton the invoices, rules, and voice keys;dynamodb:Query+GetItemonic-sends,ic-state;dynamodb:BatchWriteItemfor archiving paid chases toic-sends-archive;events:PutEventson the default bus. Nobedrock:*. - sender role:
events:ListSchedules+CreateSchedulefor the deferred-send one-offs;ses:SendRawEmailfrom the verified sender identity;dynamodb:PutItemonic-sends;secretsmanager:GetSecretValueon the pay-link signing secret. - action-handler role:
dynamodb:PutItemonic-stateandic-audit;secretsmanager:GetSecretValueon the Slack signing secret and the Sheets-API service-account secret; outbound network access tosheets.googleapis.com;dynamodb:Queryfor chase state lookup; on write-off or payment,dynamodb:BatchWriteItemfor archiving the chase toic-sends-archive. - intake-ses-parser role:
s3:GetObjectonic-raw-mime;textract:StartDocumentTextDetection+StartDocumentAnalysis;bedrock:InvokeModelon the Haiku ARN;secretsmanager:GetSecretValueon the Slack bot token. - drive-sync and intake-webhook roles:
secretsmanager:GetSecretValueon the Google service-account secret and the webhook secret;s3:PutObjecton the invoices and rules buckets; outbound network towww.googleapis.com.
Slack interactive flow
The Slack incoming webhook is the simplest delivery surface but doesn’t support interactive button responses. So the daily-review and intake-proposal messages are posted via the chat.postMessage Web API instead, with Block Kit blocks containing the action buttons. Button clicks are sent by Slack to the configured Interactivity request URL, which is the action-handler Function URL. action-handler verifies the Slack signing secret on the inbound request, parses the action_id (pause, disputed, write_off; or approve, edit, discard on intake), opens a modal if needed (Pause opens a modal; Disputed and Write-off are one-tap), and processes the response when the modal is submitted.
The Slack app needs chat:write, im:write, and the Interactivity URL configured. The bot token lives in Secrets Manager under ic/slack/bot-token. The signing secret is ic/slack/signing-secret.
Observability and cost gates
- CloudWatch Logs: all Lambdas, 7-day retention, structured JSON. Subscription filter on
"error"+"throttle"+"timeout"to a CloudWatch metric for alerting. - Alarms: chaser Lambda failures > 0 in a day (the daily tick is the one piece that has to run); sender failure rate > 1% in 24h; action-handler signature-verification failures > 5/hour (might mean the Slack secret rotated); SES bounce or complaint rate above the SES reputation thresholds (a reminder to a stale contact that hard-bounces should page).
- X-Ray: off by default. Not worth the cost at SMB volume.
- AWS Budgets: $15/month threshold, alarm at 80% and 100%, posts to SNS topic
ic-cost-alarmsubscribed to the on-call admin’s email and Slack.
Config and secrets
Service-account credentials for Drive and Sheets APIs live in Secrets Manager under ic/drive/sa (one service account with scopes for both APIs). Slack bot token and signing secret under ic/slack/*. The webhook shared secret and the pay-link signing secret under ic/webhook/* and ic/paylink/*. SES sender identity lives in IAM and the verified-domain config. The configured timezone, holiday list reference, quiet-hours window, weekend rule, and account-owner fallback all live in Parameter Store under /ic/config/. Lambdas fetch config on cold start and cache for the lifetime of the execution environment.
Deploy
GitHub Actions with OIDC into a deploy role (no long-lived keys) and AWS SAM for the stack. The opinionated bits: deploy the SES rule set as a separate stack (rule-set changes affect mail flow), turn on S3 versioning for both ic-invoices-source and ic-rules-source so a bad Drive edit can be rolled back in one click, and version the EventBridge Scheduler timezone setting so you don’t accidentally start running the daily tick in UTC after a CI rotation. SAM fits cleanly; a CDK Python stack also works. Total deployable surface: around eight Lambdas, four DDB tables, four S3 buckets, one EventBridge rule on the default bus (plus the Scheduler rules), one SES rule set, and one Budgets alarm.
That’s the full system. Six narrative posts and this engineering reference. If you want to talk about adapting it for your business, see Work with me.
All posts