Configuring AWS Lambda for Scheduled Jobs
AWS Lambda can execute recurring work without a permanently running server. EventBridge Scheduler triggers the function on a cron or one-time expression, records delivery attempts, and sends failures through a controlled retry path. This pattern suits report generation, inventory reconciliation, account checks, API automation, and other bounded jobs.
Reliability comes from treating scheduled execution as an asynchronous workflow. The scheduler decides when work should start; the function performs one well-defined action; logs and metrics reveal whether it succeeded. Keeping scheduling outside the function makes manual testing possible and avoids hiding a cron schedule inside an always-on host.
A dependable payload identifies the job and configuration version. The handler derives the relevant execution window, creates a stable run key, and uses that key to prevent duplicate work when delivery is retried. A scheduled job should therefore be designed around idempotency, not merely a successful HTTP-style response from AWS.
Australian operating windows add another layer. Sydney and Melbourne offices commonly coordinate the morning batch within local business hours, and teams often use that informal name rather than “cron job”. Australia/Sydney follows AEST and AEDT daylight-saving changes, so a 07:00 schedule should use the IANA time zone. Weekends, public holidays, and vendor support hours may still require application logic or separate schedules.
Choose the scheduling service
For new automation, EventBridge Scheduler provides the clearest fit: recurring and one-time expressions, IANA time-zone support, a flexible time window, retry configuration, and a target-specific execution role. An EventBridge rule remains useful when the job is naturally part of an event bus, while a timer on the function itself offers little visibility or delivery control.
That separation also creates useful portfolio evidence. For administrators developing cloud skills alongside their day job, practitioner career discussions can connect home-lab automation with the kinds of infrastructure projects Australian employers recognise.
Define an idempotent function contract
The handler should accept a small JSON contract and reject missing job names or configuration versions. The following Python skeleton keeps the entry point clear and emits a structured log line:
import json
def lambda_handler(event, context):
job = event.get("job")
version = event.get("version")
if not job or not version:
raise ValueError("job and version are required")
print(json.dumps({
"job": job,
"version": version,
"request_id": context.aws_request_id
}))
return {"status": "accepted", "job": job}
Use an idempotency key built from the job, intended schedule window, and configuration version. Store it in DynamoDB with a conditional write, then skip work when that key is already complete. Do not rely on Lambda’s request ID because it is suited to tracing, not business deduplication. Set a timeout that fits the workload, apply bounded timeouts to external calls, and allow unexpected exceptions to fail so retries and alerts can operate correctly.
Configure least-privilege access
The Scheduler execution role trusts scheduler.amazonaws.com and may pass only the target role and invoke only the intended Lambda function. The Lambda execution role separately trusts lambda.amazonaws.com and grants access to resources such as DynamoDB, CloudWatch Logs, or Secrets Manager. A minimal trust statement for the scheduler role is:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "scheduler.amazonaws.com"},
"Action": "sts:AssumeRole"
}]
}
Keep these roles distinct:
| Role | Trusted principal | Typical permissions |
|---|---|---|
| Scheduler execution role | scheduler.amazonaws.com |
Pass the named target role and invoke the function |
| Lambda execution role | lambda.amazonaws.com |
Access only required application resources |
| Cross-account target role | Target account principal | Invoke the Lambda function in that account |
Define these relationships in Terraform, CloudFormation, or the AWS CLI so role changes remain reviewable. Reference a Lambda alias or qualified version in the target rather than $LATEST, and separate development, test, and production schedules with distinct names and tags.
Create the recurring schedule
Save the following as schedule.json; the target input tells the handler which job and configuration version to run.
{
"Name": "weekday-inventory-sync",
"ScheduleExpression": "cron(0 7 ? * MON-FRI *)",
"ScheduleExpressionTimezone": "Australia/Sydney",
"FlexibleTimeWindow": {"Mode": "OFF"},
"Target": {
"Arn": "arn:aws:lambda:ap-southeast-2:123456789012:function:inventory-sync:live",
"RoleArn": "arn:aws:iam::123456789012:role/scheduler-target-role",
"Input": "{\"job\":\"inventory-sync\",\"version\":\"1\"}"
}
}
Create it with aws scheduler create-schedule --cli-input-json file://schedule.json --region ap-southeast-2. The cron expression means 07:00 on weekdays in Australia/Sydney. The scheduler applies daylight-saving changes to that local schedule, whereas a UTC schedule would shift its local timing. Keep FlexibleTimeWindow set to OFF for exact batch starts, or enable a window for workloads that can tolerate delay. One-time expressions use at() and can delete the schedule after completion.
Validate without waiting for cron with aws scheduler test-schedule --name weekday-inventory-sync. This confirms target delivery, not necessarily eventual business completion when Lambda runs asynchronously, so inspect the function’s CloudWatch logs and idempotency record as well. Invoke the handler directly with a representative event for quicker debugging.
Secure external and hybrid dependencies
Store credentials in AWS Secrets Manager or Parameter Store, not plaintext environment variables, and restrict KMS decryption to the Lambda execution role. For hybrid dependencies, define VPC subnets, routing, and egress deliberately; a Lambda function in a VPC needs a NAT path for public internet access or an endpoint for each AWS service it calls.
When scheduled work sits alongside on-premises services behind load balancers or web application firewalls, consistent TLS, routing, and availability policies matter. The application delivery guidance at IT Diversified provides relevant operational context. Australian teams can place workloads in ap-southeast-2 for Sydney or ap-southeast-4 for Melbourne to keep data near primary operating regions, then design a tested cross-region recovery path.
Monitor failures and evolve safely
Monitor both layers. EventBridge Scheduler metrics show target-delivery attempts and throttling, while Lambda metrics and CloudWatch Logs reveal errors, duration, concurrency, and downstream failures. Include the job name and run key in structured logs, emit success and failure metrics, and create alarms for repeated failures rather than a single missed execution.
Scheduler can retry target delivery and place undeliverable events on an SQS dead-letter queue. Lambda asynchronous invocation can also retry and can use a separate dead-letter queue, so configure the queues deliberately and avoid treating acceptance by Lambda as proof that the business operation finished. Version the function and schedule together, test the dead-letter queue path, and document the owner, cadence, timeout, and expected output for each job.