Serverless computing is a cloud computing execution model in which the cloud provider dynamically allocates machine resources consumed by the service instances. Scale-to-zero is an important serverless computing concept. It describes how serverless runtimes automatically scale out to handle the increased load, and scale to zero when the runtime is not in use.
If you’d like to learn more about developing Lambda functions, you can do so here. This blog post assumes you have a Lambda function ready to deploy using the Harness platform. Let’s share how to do a simple AWS Lambda deployment.
What do I need to get deploying?
Deploying your AWS Lambda functions to Harness is fairly simple. You’ll want to ensure you have an AWS account that can connect to Harness.
Before you begin, ensure that you’ve installed a Harness Delegate within your AWS VPC. You’ll need this delegate to connect to your S3 bucket(your S3 bucket serves as the artifact source) and Lambda functions. This delegate may be a Shell Script Delegate installed on an EC2 instance or an ECS Delegate installed on an ECS cluster. If you are installing the Delegate on an AWS EC2 instance, sure you provide the AmazonEC2FullAccess policy. Otherwise, for an existing ECS Cluster, you’ll want to provide the AmazonEC2ContainerServiceforEC2Role policy.
For the Delegate to perform operations with Lambda, you’ll need an IAM role with the following policies:
- AWSLambdaFullAccess (arn:aws:iam::aws:policy/AWSLambdaFullAccess)
- AWSLambdaRole (arn:aws:iam::aws:policy/service-role/AWSLambdaRole)
In this example, we’ll use a single delegate to connect to both the S3 bucket and the lambda function. Attach the AmazonS3ReadOnlyAccess policy to your delegate. This delegate will need an S3 policy to access the S3 bucket you set up.
I highly recommend going to this Harness Delegate and adding a tag to the Selectors section. This allows you to reference this specific Delegate to be used when you create the AWS Cloud Provider.
The final thing you need to ensure is you’ve set up an AWS Cloud Provider with an IAM role used by the installed Harness Delegate. Click here to view our documentation on adding your AWS instance as a Harness Cloud Provider.
And with this section, you are ready to create your Lambda deployments.
Harness your AWS Lambda Functions
Here are the steps to deploying your AWS Lambda Functions. Within Harness create a new, or use an existing Harness Application for your Lambda deployment pipeline. We’ll be using this Application to define the necessary information about our deployment. Fill out the following Application details:
- Service: You’ll need to define a name and artifact type. Edit this newly created service with the following steps:
- Click +Add Artifact Source
- Modify the Deployment Specification, by clicking the Lambda Function Specification. Here you will modify the default values for Runtime, memory size and Execution timeout
- Add a function by providing a function name, handler, and other details.
- Hit submit to confirm these details about your Lambda.
- Click +Add Environment, provide the required fields and hit Submit
- Click on the newly created environment and select the +Add Infrastructure Definition option.
- Provide the required information, and use AWS Lambda as the Deployment Type.
- Hit Submit to confirm the infrastructure definition.
- Click +Add Workflow
- Enter the required information to define a Basic Deployment. You’ll use the Environment, Service, and Infrastructure Definition you set up earlier in this step.
- Hit Submit to save your workflow
- Click on your newly created workflow.
- Optionally you may decide to add additional steps( e.g: for verification) to your workflow.
- When you are ready to start your deployment hit Deploy on this screen.
Finally, watch your Lambda deploy!
Here’s a video to follow along with the steps shared above.
Once your deployment has completed, you’ll see a success or failure status. This is how to define the necessary information to do an AWS Lambda deployment using Harness.
Optionally, you may also choose to define the following Application details:
- Pipelines to utilize your workflows, and
- Triggers to automatically deploy your application services using your pipelines.
I would also recommend using AWS CloudWatch to verify your deployment and monitor your production services. You learn can learn how to do that here.
I hope this blog post helps you get started with Lambda deployments using Harness. If you’d like to try Harness for free you can, just click here to sign up.