> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/3.0/use-deployments/serverless/overview.md).

# Overview

Deploy AWS Lambda functions using the Serverless Framework with Harness CD.

A Serverless Lambda stage deploys your Lambda functions to AWS using the [Serverless Framework](https://www.serverless.com). You provide a `serverless.yaml` manifest that defines your functions, point Harness at your AWS account and region, and Harness packages, deploys, and rolls back automatically using CloudFormation.

***

## What you will learn

This page covers the following topics:

* The AWS IAM permissions required for Serverless Lambda deployments.
* How to set up a Serverless Lambda deployment stage in Harness.
* How to configure the service, environment, and execution steps.
* Stage settings for execution controls and the Kubernetes runtime environment.

***

## Before you begin

Before you add a Serverless Lambda deployment stage, make sure you have:

* An **AWS connector** configured with an IAM role that has the minimum permissions described in [AWS IAM permissions](#aws-iam-permissions).
* A **`serverless.yaml` manifest** stored in a Git repository or AWS S3.
* A **deployment artifact** (ZIP file or container image) stored in Artifactory, S3, ECR, or Harness Artifact Registry.
* A **Kubernetes cluster** available for the delegate and containerized step execution.

***

## AWS IAM permissions

The IAM role attached to your AWS connector needs the following managed policies:

| Policy                               | Purpose                                                                    |
| ------------------------------------ | -------------------------------------------------------------------------- |
| `AWSCloudFormationFullAccess`        | Create and manage the CloudFormation stack that Serverless deploys through |
| `AWSLambda_FullAccess`               | Create and update Lambda functions                                         |
| `AmazonS3FullAccess`                 | Upload deployment packages and CloudFormation artifacts to S3              |
| `IAMFullAccess`                      | Create and manage the Lambda execution role defined in `serverless.yaml`   |
| `CloudWatchLogsFullAccess`           | Create log groups for Lambda function output                               |
| `AmazonEC2ContainerRegistryReadOnly` | Pull a container image from ECR (if using an ECR artifact)                 |

The exact permissions required depend on the AWS services declared in your `serverless.yaml`. Functions that define API Gateway events, SQS triggers, or DynamoDB streams require additional permissions for those services. Go to [Serverless Framework credentials](https://www.serverless.com/framework/docs/providers/aws/guide/credentials) to review the full recommended policy.

***

## Set up a Serverless Lambda deployment

1. Go to **Pipelines** and click **Create Pipeline**.
2. Enter a pipeline name. Under **Storage**, select **Inline** or a Git repository. Click **Create**.
3. A default **Stage 1** is added. You can edit it directly, but the deployment strategy selection step will be skipped. To choose a strategy, delete **Stage 1** and click **+** to add a new stage.
4. Select **Deploy** and click **Set Up Stage**.
5. Enter a stage name and set **Deployment Target** to **Serverless Lambda**. Click **Next**.

The wizard walks you through five steps: service, environment, execution, deployment strategy, and runtime.

**Step 5: Runtime:** The following table describes the available runtime options for a Serverless Lambda stage:

| Option                                | Description                                                                                                                                                                                                   |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Run on Harness Cloud**              | Harness manages the stage host. A Kubernetes runtime environment is still required in **Runtime Environment** for the Package, Deploy, and Rollback step containers.                                          |
| **Run on Delegate**                   | A Harness delegate orchestrates the stage. Use **Delegate tag** to route execution to a specific delegate pool. Configure **Runtime Environment** in the stage settings to specify where step containers run. |
| **Run as Ephemeral Pod (Kubernetes)** | The stage runs as a pod inside a Kubernetes cluster.                                                                                                                                                          |

For Serverless Lambda, **Run on Delegate** is the most common choice. The delegate manages communication with AWS and Kubernetes, while the Package, Deploy, and Rollback step containers run inside the Kubernetes cluster configured in **Runtime Environment**.

***

## Service

A **service** represents what you deploy. For Serverless Lambda, it holds the `serverless.yaml` manifest (your function definitions, event triggers, providers, and resources), the artifact source (ZIP or container image), and service-level variables.

Services are independent of pipelines; configure one once and reuse it across stages and pipelines.

Go to [Serverless services](/continuous-delivery/3.0/use-deployments/serverless/serverless-services.md) to configure manifest sources, artifact sources, and expression handling.

***

## Environment and infrastructure

An **environment** is a logical deployment target such as development, staging, or production. An **infrastructure definition** within an environment points to the AWS account, region, and Serverless stage where Harness deploys the functions.

The infrastructure definition references an **AWS connector** that authenticates to AWS. The connector uses a **delegate** running in your network to reach the AWS APIs; no inbound access to your environment is required.

Go to [Serverless infrastructure](/continuous-delivery/3.0/use-deployments/serverless/serverless-infrastructure.md) to configure environments, infrastructure definitions, and connectors.

***

## Deployment strategies

Serverless Framework deployments use a **full deploy** strategy: Harness packages your functions, creates or updates the CloudFormation stack, and activates the new Lambda versions. If the deployment fails, Harness restores the CloudFormation stack to its previous state.

| Strategy        | What it does                                                                                                                                                                                                                                                     |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Full deploy** | Packages the manifest and artifact, then runs `serverless deploy` to create or update the CloudFormation stack and register the new Lambda function versions. Harness captures the previous stack state before deployment so rollback restores it automatically. |

For canary routing or traffic-shifted Lambda deployments using function aliases, use the AWS Lambda deployment type.

***

## Stage settings

Each stage has settings accessible from the stage editor, organized into five sections: **Deploy**, **Code & build**, **Inputs & outputs**, **Execution controls**, and **Runtime Environment**.

### Inputs & outputs <a href="#inputs-and-outputs" id="inputs-and-outputs"></a>

The **Inputs & outputs** section defines the stage's inputs, environment variables, and outputs. Use this section to declare values the stage accepts as runtime inputs, environment variables available to step containers during execution, and outputs the stage exposes to downstream stages.

### Execution controls <a href="#execution-controls" id="execution-controls"></a>

The **Execution controls** section sets conditions, looping strategy, concurrency, failure strategy, and timeout for the stage.

**On failure:** Defines what Harness does when the stage fails. For Serverless deployments, `stage-rollback` triggers the Serverless Rollback step and restores the previous CloudFormation stack state.

```yaml
on-failure:
  errors: all
  action: stage-rollback
```

**Strategy:** Configures a looping strategy so the stage runs multiple times across a matrix of values, for example to deploy the same service to multiple AWS regions.

```yaml
strategy:
  matrix:
    region: [us-east-1, eu-west-1]
  max-concurrency: 2
```

### Runtime environment <a href="#runtime-environment" id="runtime-environment"></a>

The **Runtime Environment** section configures where the stage's step containers execute. The following fields are available:

| Field            | Description                                                                                                                                        |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Platform**     | Optional. Add platform-level overrides for step execution.                                                                                         |
| **Runtime**      | Select **Kubernetes** and provide the **Namespace** and **Connector** for the cluster that runs the Package, Deploy, and Rollback step containers. |
| **Shared paths** | Optional. Mount additional volume paths into all step containers in the stage.                                                                     |

```yaml
runtime:
  kubernetes:
    namespace: <your-k8s-namespace>
    connector: <your-k8s-connector>
    pull: always
```

Without a Kubernetes runtime configured, the Package, Deploy, and Rollback steps will not run.

***

## Next steps

* Go to [Serverless services](/continuous-delivery/3.0/use-deployments/serverless/serverless-services.md) to configure manifests and artifact sources.
* Go to [Serverless infrastructure](/continuous-delivery/3.0/use-deployments/serverless/serverless-infrastructure.md) to configure environments and infrastructure definitions.
* Go to [Serverless deployment](/continuous-delivery/3.0/use-deployments/serverless/serverless-deployment.md) to set up the execution steps and rollback behavior.
* Go to [Step library](/continuous-delivery/3.0/use-deployments/serverless/step-library.md) to review individual step parameters.

{% @harness-feedback/feedback %}
