Scheduling Content Publication with Amplify Gen 2
Design scheduled publishing with UTC timestamps, idempotent mutations, bounded retries, cache revalidation, and visible failure records.
Scheduled publishing needs more than a date field. I separate the editor's intent, the stored UTC time, the public publication state, and the job that applies the change. That separation lets an editor reschedule a post, lets a job retry, and prevents two invocations from publishing twice.
Amplify supports scheduled Functions through natural-language intervals or cron expressions backed by EventBridge. The Amplify scheduled Functions documentation provides the current resource syntax. The publishing rules still belong in application code and data authorization.
Store an unambiguous publication time
I ask the editor for a local date and timezone, then store an ISO UTC timestamp. I keep the original timezone only when the editorial interface needs to show the intended wall-clock time. Comparing UTC values avoids daylight-saving and server-timezone surprises.
The record also stores a state such as draft, scheduled, published, or failed. A future timestamp alone does not tell the interface whether an editor approved publication.
Run a bounded scheduled query
The scheduled function queries records that are approved, scheduled, and due at or before the current UTC time. I use a limit and pagination so one delayed run cannot exceed its execution window. Records scheduled far in the future stay outside the result.
The function receives explicit data access through a resource authorization rule. It does not use public write access to make scheduled publishing convenient.
Make the mutation idempotent
The update checks the current state before writing. If another invocation already published the record, the second invocation exits without changing the publication timestamp. I preserve the first successful timestamp and attach an operation ID when the workflow needs an audit trail.
Idempotency also covers side effects. Search notifications, cache refreshes, and email announcements should tolerate a repeated event or use their own deduplication key.
Handle retries and partial failure
I distinguish a data conflict from a temporary network error and a permanent validation problem. Temporary failures can retry with a cap. Invalid records move to a failed state with a safe reason that an editor can act on.
I avoid marking the record published before required side effects succeed unless the product explicitly accepts delayed revalidation. The order must match what "published" means to the public site.
Refresh the pages that changed
After the data mutation succeeds, the system invalidates the article route, blog index, relevant category pages, and any sitemap cache. The mapping comes from the changed record rather than a site-wide purge.
I log which paths or tags were requested and verify a public fetch. Revalidation can be asynchronous, so the monitor checks the final page rather than treating the invalidation call as proof.
Operate the schedule
I alarm on function errors, old scheduled records, and a growing failed queue. A dashboard that only counts successful invocations can miss a job that ran but selected no records because of a bad filter.
- Store approved state and UTC time.
- Query due records in bounded pages.
- Use idempotent updates.
- Record actionable failures.
- Verify the public page after revalidation.
Need help with Amplify?
Terry Hunt Dev builds content workflows and scheduled AWS jobs through AWS development services. If your publication queue skips or duplicates posts, request a workflow review through the contact page.