Migrate from AWS Lambda to Knative

Updated at:

Migrate serverless applications from AWS Lambda to ACK Knative. It covers migration assessment, architecture mapping, application refactoring, event integration, deployment, and cutover recommendations to help you evolve from a cloud-vendor-specific FaaS to an open Kubernetes-based Serverless platform with lower risk.

Advantages of Knative

Knative is an open-source Serverless framework built on Kubernetes clusters. It provides a cloud-native, cross-platform Serverless orchestration standard by combining container building, workload management, and an event model. Its main advantages are:

  • Focus on business logic: With simple application configuration and automatic scaling, Knative lets developers focus on business logic, reducing operational overhead and the need to manage underlying resources.

  • Automatic scaling and version management: Knative automatically scales instances to zero when there is no traffic to save resources, and provides features such as version management and canary releases.

  • Event-driven: Knative provides a complete event model that makes it easy to integrate events from external systems and route them to the appropriate services or functions for processing.

  • Standardization: Deploying business code to a Serverless platform requires handling source-code compilation, deployment, and event management. Serverless and FaaS solutions from the community and cloud vendors lack consistent standards. Knative provides a standard, general-purpose Serverless framework.

Conduct the migration in three phases: pre-migration, migration, and post-migration. The following sections describe the assessment and planning methods, implementation and cutover actions, and post-launch verification and optimization for each phase.

1. Pre-migration: assessment and planning

The goal of the pre-migration phase is to minimize uncertainty. First, inventory existing functions and identify the scope of changes. Then map the AWS Lambda model to Knative, select the migration path and target architecture, and finally group and prioritize the applications and prepare the platform's foundational capabilities.

Application inventory and assessment

Before you start the migration, complete an application inventory to identify which Lambda functions can be migrated directly and which require modifications. Focus on the following assessment dimensions.

Triggers

Runtime and dependencies

State and sessions

Timeout, concurrency, and cold-start sensitivity

Identify the trigger sources of each Lambda, such as API Gateway, Application Load Balancer, or S3. Different trigger sources have different migration paths to Knative. Some are suitable for conversion to HTTP services, while others fit well with message systems or event buses.

Confirm the language and version currently used by each Lambda, its third-party dependencies, and whether it relies on local binary libraries.

Lambda is inherently suited for stateless processing. After migrating to Knative, keep the stateless design. Verify the following:

  • Whether the function relies on instance reuse to cache data.

  • Whether it uses local memory to store sessions.

  • Whether it relies on an idempotency mechanism.

Evaluate the current function's performance characteristics:

  • Average response time.

  • P95 / P99 latency.

  • Peak concurrency.

  • Cold-start sensitivity.

  • Whether long requests or streaming responses are required.

Capability mapping between AWS Lambda and Knative

After completing the assessment, map AWS Lambda concepts to the Knative runtime model as the basis for subsequent path and architecture design.

AWS Lambda

Corresponding Knative capability

Description

Lambda Function

Knative Service / Container

Shift from a function model to a container model.

Lambda Runtime

Application process in the container image.

The runtime environment is defined by the container image.

Handler

HTTP handler or event consumer entry point

Refactor the function entry into HTTP routes or message consumption logic.

API Gateway

Kourier / Istio / ALB

Knative built-in routing or integration with an external gateway.

Lambda URL

Knative Service URL

Automatically generated service URL.

IAM Role

Kubernetes ServiceAccount + cloud vendor identity binding

Use ServiceAccount to integrate with the cloud platform permission system.

Lambda Alias / Version

Knative Revision + Traffic Split

Built-in version management and traffic distribution.

Reserved Concurrency

Knative concurrency parameters + Knative Pod Autoscaler (KPA) configuration

Provides fine-grained control over per-instance concurrency and scaling behavior.

Note

Lambda is a function model, while Knative is essentially a Serverless abstraction on top of a container model. The migration is not just about "switching to another runtime platform"—it involves refactoring the "function entry" into an "HTTP service or event consumer".

Migration path selection

Two common migration paths are available:

Path 1: Migrate API-style Lambda applications to Knative Serving

Suitable for Lambda functions originally triggered by API Gateway, such as webhooks, REST APIs, lightweight inference endpoints, and backend microservice APIs. The core idea is to refactor the Lambda handler into an HTTP service, package it as a container image, deploy it as a Knative Service. Then use Knative’s built-in domain names, Ingress, and traffic management capabilities to expose the service.

Path 2: Migrate event-driven Lambdas to Knative Eventing

Suitable for functions triggered by object storage events, message queue events, publish/subscribe events, scheduled tasks, or data stream events. For these scenarios, choose the Broker/Trigger model of Knative Eventing based on the target architecture.

Typical migration architectures

After the path is decided, refer to the following three typical architectures to plan the target topology.

Scenario 1: API Gateway + Lambda → Knative Service

Before migration: Client → API Gateway → Lambda
After migration:  Client → Ingress/Gateway → Knative Service

Scenario 2: S3/SNS/SQS-triggered Lambda → object events/message systems + Knative

Before migration: S3/SNS/SQS → Lambda
After migration:  Object Storage / Message Queue / Event Bus → Knative Eventing → Knative Service

Or:

Queue/Topic → Consumer Container → Knative Service

Scenario 3: EventBridge scheduled tasks → CronJob / Eventing

Before migration: EventBridge Schedule → Lambda
After migration:  CronJob / Event Source / EventBridge Schedule → Knative Service

Application grouping and migration priorities

Classify existing Lambdas by complexity, from easiest to most complex:

  • Category A: API-style, stateless, and with few dependencies. Migrate first.

  • Category B: Message-driven. Requires event integration refactoring.

  • Category C: Strongly dependent on AWS services. Requires architecture adjustments before migration.

Migrate simple HTTP services first: prioritize Lambdas triggered by API Gateway, which have the lowest refactoring cost and are the easiest way for the team to build practical experience with Knative. Then expand to event-driven scenarios.

Platform foundation preparation

Prepare the following foundational capabilities on Knative in advance to avoid last-minute additions during migration:

  • Image registry.

  • Ingress / domain names / TLS.

  • Observability stack.

  • Configuration and secret management.

  • CI/CD pipeline.

  • Canary release capability.

2. Migration: implementation and cutover

After completing the assessment and platform preparation, move on to the actual refactoring and rollout. First, refactor the code, build the images, and deploy to Knative. Then tune concurrency and scaling, and improve the observability stack. Finally, complete the rollout through canary traffic switching.

Code refactoring

Refactor from Lambda handler to HTTP entry point

The most common code shape in Lambda is (Python Lambda example):

def handler(event, context):
    name = event.get("queryStringParameters", {}).get("name", "world")
    return {
        "statusCode": 200,
        "body": f"Hello, {name}"
    }

After migrating to Knative, refactor it into a standard web service (Python Flask example):

from flask import Flask, request

app = Flask(__name__)

@app.route("/", methods=["GET"])
def hello():
    name = request.args.get("name", "world")
    return f"Hello, {name}", 200

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

Package as a container image

Create a Dockerfile:

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py .
ENV PORT=8080
CMD ["python", "app.py"]

Create requirements.txt:

flask==3.0.0

Deploy to Knative

The following is a minimal Knative Service example:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-service
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/min-scale: "0"
        autoscaling.knative.dev/max-scale: "20"
    spec:
      containerConcurrency: 10
      containers:
      - image: registry.example.com/hello:1.0.0
        ports:
        - containerPort: 8080

Deploy:

kubectl apply -f service.yaml

View the service:

kubectl get ksvc

View the route URL:

kubectl get route

Concurrency, scaling, and cold-start tuning

Lambda and Knative do not have identical scaling models. Do not directly reuse the original Lambda timeout and capacity settings. After migration, rerun load tests and tune the following Knative parameters.

containerConcurrency

Set the containerConcurrency field as follows to control the concurrency each instance can handle:

spec:
  template:
    spec:
      containerConcurrency: 10

Set the concurrency based on your specific scenario:

  • Low concurrency: more stable and suitable for CPU-intensive tasks.

  • High concurrency: fewer instances and lower cost, but requires evaluation of application thread safety and resource bottlenecks.

Minimum replicas

If your workload is sensitive to cold starts, set the min-scale annotation as follows to control the minimum number of replicas:

metadata:
  annotations:
    autoscaling.knative.dev/min-scale: "1"

Maximum replicas

To prevent runaway resource usage caused by traffic spikes, set the max-scale annotation as follows to control the maximum number of replicas:

metadata:
  annotations:
    autoscaling.knative.dev/max-scale: "50"

Resource requests and limits

Set the resources field as follows to properly allocate CPU and memory resources:

resources:
  requests:
    cpu: "500m"
    memory: "512Mi"
  limits:
    cpu: "1"
    memory: "1Gi"

Build the observability stack

Lambda commonly relies on CloudWatch. After migrating to Knative, build a unified observability stack before traffic switching:

  • Logs: Based on SLS Collect Logs from Knative Services.

  • Metrics: Ingest monitoring data into Prometheus and view Knative performance metrics in Grafana.

  • Tracing: Integrate OpenTelemetry for end-to-end trace collection, and use Jaeger or Tempo to visualize request call chains.

  • Alerts: Use Alertmanager or an enterprise monitoring platform, or use SLS alert monitoring rules Configure alerting for Knative Services.

Canary release and traffic switching

One of Knative's key advantages is built-in Revision and traffic allocation capability, which is well suited for canary migration.

Canary release example

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-service
spec:
  traffic:
  - revisionName: hello-service-v1
    percent: 90
  - revisionName: hello-service-v2
    percent: 10
  template:
    metadata:
      name: hello-service-v2
    spec:
      containers:
      - image: registry.example.com/hello:2.0.0

This lets you:

  • Validate the migrated version with low traffic.

  • Roll back quickly.

  • Compare the performance of the old and new versions.

Recommended cutover steps

  1. Deploy the new version on Knative.

  2. Use a test domain to validate functionality.

  3. Route a small percentage of traffic as a canary.

  4. Validate logs, latency, and error rates.

  5. Cut over all traffic.

  6. Keep Lambda running for a while as a fallback plan.

Progressive migration of event-driven applications

For event-driven Lambdas such as messages, object events, and scheduled tasks, dedicated planning is required. Full-scale migration in one step is not recommended.

If your business code is directly coupled to the API Gateway or EventBridge event schema, the migration cost increases significantly. First, abstract the input/output model to decouple event parsing from business logic. Then refactor each event source into the Knative Eventing Broker/Trigger model or a self-built consumer container. For each event source, perform low-traffic validation first, and decommission the corresponding Lambda only after confirming no issues.

3. Post-migration: verification and continuous optimization

Completing the traffic switch does not mean the migration is over. After go-live, you still need to continuously monitor core metrics, keep rollback paths in place, and ensure that the observability stack continues to function.

Core metrics to monitor continuously

Dual-stack operation and rollback plan

Continuous improvement of the observability stack

The post-migration dashboards should cover at least the following metrics so that platform-specific behavior differences (such as cold-start frequency and KPA scaling fluctuations) can be detected in time:

  • Request volume.

  • Error rate.

  • Latency distribution.

  • Number of instances.

  • Cold-start frequency.

  • External dependency call latency.

Before officially decommissioning Lambda, always maintain a complete rollback path:

  • Dual-stack operation capability.

  • Traffic canary capability.

  • Observability dashboards.

  • Fast rollback path.

As described in step 6 of Recommended cutover steps, keep Lambda running for some time after the traffic switch is complete. Confirm that the new version runs stably under real production traffic before officially decommissioning the original functions and related resources such as API Gateway.

Migrating from "fully managed cloud vendor functions" to "Kubernetes-based Serverless" provides greater platform visibility, but also requires you to continually build out the logging, metrics, tracing, and alerting systems to maintain monitoring coverage as your business grows.

Summary

Migrating from AWS Lambda to Knative is not just a simple platform replacement. It is an architectural evolution from a "cloud-vendor-specific function platform" to an "open container-based Serverless platform".

The key benefits of this migration include:

  • Reduced platform lock-in.

  • Greater control over the runtime environment.

  • A unified application delivery model.

  • More flexible scaling and traffic management capabilities.

  • A foundation for multi-cloud, hybrid cloud, and AI scenarios.

Follow the order in this topic, starting with the easiest HTTP Lambdas and progressively migrating more complex functions to Knative.

Related documents