AWS Logo
Menu
Migrating Curl CronJobs to Lambda from K8s Deployments

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.

Universal curl image:

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,

Lambda Terraform Module:

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:
FileResourceAttributes & Description
events.tfaws_cloudwatch_event_ruleCron-based scheduling for Lambda
aws_cloudwatch_event_targetBinds Lambda to EventBridge
aws_lambda_permissionGrants EventBridge invoke rights
iam.tfaws_iam_role, aws_iam_policyExecution, VPC, and ECR policies
lambda.tfaws_lambda_functionCore Lambda configuration
sg.tfaws_security_groupSG allowing egress (0.0.0.0/0)
variables.tfInputs for customization
Module Structure:
events.tf
iam.tf
lambda.tf
sg.tf
variables.tf

Common Config

providers_aws.tf
versions.tf
pipeline_config

Lambda deployment:

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 (stgfolder).

Verify the Deployment:

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.
     

Comments