2 - Services for Lambda

Updated 3 weeks ago by Michael Cretzman

This topic describes how to create a Harness Application and adds a Service that uses a function file, runtime, and handler information to define the Lambda function to deploy.

Harness Application Setup

The following procedure creates a Harness Application for a Lambda deployment.

An Application in Harness represents a logical group of one or more entities, including Services, Environments, Workflows, Pipelines, Triggers, and Infrastructure Provisioners. Applications organize all of the entities and configurations in Harness CI/CD. For more information, see Application Components.

To create the Harness Application, do the following:

  1. In Harness, click Setup.
  2. Click Add Application. The Application dialog appears.
  3. Give your Application a name that describes your microservice or app. For the purposes of this guide, we use the name ExampleApp.
  4. Click SUBMIT. The new Application is added.
  5. Click the Application name to open the Application. The Application entities are displayed.

Lambda Services

There are different types of Harness Services for different deployment platforms. The Lambda type includes Lambda-specific settings, including your function file and runtime and handler information.

To add the Lambda Service, do the following:

  1. In your new Application, click Services. The Services page appears.
  2. In the Services page, click Add Service. The Service dialog appears.
  3. In Name, enter a name for your Service, such as aws-lambda. You will use this name to select this Service when you set up a Harness Environment and Workflow.
  4. In Description, enter a description for your Service.
  5. In Artifact Type, select AWS Lambda.
  6. Click SUBMIT. The new Service is displayed.

Next, we will walk through how to set up the Lambda Function Specification and use the Service features.

Add Lambda Function File

An Artifact Source in a Lambda Service is the Lambda function file you want to deploy. The Artifact Source uses the AWS Cloud Provider you set up for your Harness account, as described in Connectors and Providers Setup.

To add an Artifact Source to this Service, do the following:

  1. In your Lambda Service, click Add Artifact Source, and then click Amazon S3. For information on using a Custom Artifact Source, see Custom Artifact Source. The Amazon S3 Artifact Source dialog appears.
  2. In Cloud Provider, select the AWS Cloud Provider you set up in Connectors and Providers Setup.
  3. In Bucket, select the S3 bucket containing the Lambda function zip file you want.
  4. In Artifact Path, select the Lambda function zip file containing your functions. Here is how your S3 bucket and file relate to the Artifact Source dialog:

The Meta-data Only option is selected by default. Harness will not copy the actual zip file. During runtime, Harness passes the metadata to Lambda where it is used to obtain the file.

  1. Click SUBMIT. The Lambda function file is added as an Artifact Source.

Lambda Function Specification

In Lambda Function Specification, you provide details about the Lambda functions in the zip file in Artifact Source.

Click Lambda Function Specification. The AWS Lambda Function Specifications dialog appears.

The details you provide are very similar to the options in the AWS CLI aws lambda create-function command. For more information, see create-function from AWS.

Some of the options are specified in Harness Environments and Workflows to help you reuse the Service with multiple Environments and Workflows.

By default, the AWS Lambda Function Specifications dialog displays a function. If you have multiple Lambda functions in the zip file in Artifact Source, click Add Function and provide details for each function.

For each function in the Functions section, enter the following function information:

  • Runtime - The Lambda runtime that executes your function. This is the runtime for all functions in this spec. AWS can change its runtime version support. For example, AWS no longer supports nodejs6.10.
  • Function Name - The name of your function. This name will become part of the function ARN in Lambda.
    Harness uses default variables for the name that include your Harness Application, Service, and Environment names (${app.name}_${service.name}_${env.name}). If you use these, you need to append a unique suffix to each function name, for example ${app.name}_${service.name}_${env.name}_my-function. Or you can replace the entire name.
  • Handler - The method that the runtime executes when your function is invoked. The format for this value varies per language. See Programming Model for more information.

For example, let's look at a Node.js function in a file named index.js:

exports.handler =  async function(event, context) {
console.log("EVENT: \n" + JSON.stringify(event, null, 2))
return context.logStreamName
}

The value of the Handler setting is the file name (index) and the name of the exported handler module, separated by a dot. In our example, the handler is index.handler. This indicates the handler module that's exported by index.js.

  • Memory Size - The amount of memory available to the function during execution. Choose an amount between 128 MB and 3,008 MB in 64 MB increments. There are two Execution Timeout settings. A default setting and a function-specific setting.
  • Execution Timeout - The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds. There are two Execution Timeout settings. A default setting and a function-specific setting.

When you are done, the AWS Lambda Function Specifications dialog will look something like this:

When you are done, click SUBMIT. You function is added to the Service.

Config Variables and Files

Config variables and files are available in all Harness Service types. For more information, see Configuration Variables and Files.

Next Step


How did we do?