
Migrating Curl CronJobs to Lambda from K8s Deployments
Migrated k8s cronjobs using a universal curl image to AWS Lambda, where curl commands are passed dynamically for lightweight, flexible execution.
Published Apr 26, 2025
A centralized and standardized setup for deploying Lambda-based cron jobs using Terraform modules, especially those utilizing a universal
curl
container image for simple HTTP-based tasks.First, prepare a universal curl image that will be used to execute dynamically passed curl commands. In this example, Node.js is used to build the curl image.
Dockerfile
handler.js
package.json
Command to build & push
amd64
universal curl image,In the
lambda/lambda.tf
file, define the Lambda services and cron job schedule.The Terraform configuration uses an S3 backend for state management. You should configure the backend by ensuring the
backend.tf
points to the appropriate backend configuration for your environment.Additionally, ensure that the AWS provider is properly configured in
providers_aws.tf
, which is symlinked from common config.Key Resources and Attributes:
File | Resource | Attributes & Description |
---|---|---|
events.tf | aws_cloudwatch_event_rule | Cron-based scheduling for Lambda |
aws_cloudwatch_event_target | Binds Lambda to EventBridge | |
aws_lambda_permission | Grants EventBridge invoke rights | |
iam.tf | aws_iam_role , aws_iam_policy | Execution, VPC, and ECR policies |
lambda.tf | aws_lambda_function | Core Lambda configuration |
sg.tf | aws_security_group | SG allowing egress (0.0.0.0/0) |
variables.tf | Inputs for customization |
Module Structure:
events.tf
iam.tf
lambda.tf
sg.tf
variables.tf
providers_aws.tf
versions.tf
pipeline_config
In the
lambda.tf
file, define the Lambda services and cron job schedule. .terraenv
backend.tf
data.tf
lambda.tf
variables.tf
Same approach can be applied in staging (
stg
folder). Once the deployment completes, verify the following resources:
- Lambda Functions: Go to the Lambda Console to check that the Lambda functions are deployed and configured correctly.
- EventBridge Rules: Verify that the EventBridge cron jobs are created in the EventBridge Console.
- CloudWatch Logs: Check the logs for Lambda functions in CloudWatch Logs.