Serverless and Harness — Better Together
After part one and part two, we are starting to get dangerous in the serverless world. We have created our first or first few AWS Lambda functions and know architectural concerns around leveraging a serverless implementation. With serverless implementations and especially AWS Lambda, editing on the fly is easy. Let’s not forget our SDLC discipline.
Don’t forget the SDLC!
Remember the reason why there is a business control restricting folks from production? The main reason is so that we don’t go hot patching in production. The same justification can be true for a Lambda. Though patching or modifying a Lambda is super easy vs a traditional system. We can just modify in-line the code that the Lambda would run. If we introspect the Lambda that we invocated in part one, we could edit the NodeJS script in-line with the AWS Lambda editor, oh my or oh yes!
With the ease of modification of the Lambda, important not to forget our SDLC discipline. By integrating AWS Lambda as part of your Harness Pipeline, you can ensure that the diligence and confidence your SDLC / Continuous Delivery process instills is followed.
Your first Lambda integration
If you have not already, you can set up AWS as a Cloud Provider in your Harness Platform. Though this will require the installation of a Harness Delegate which can be installed a few ways on AWS. I recently posted on the Harness Community how to install and let AWS ECS Fargate install and run a Harness Delegate.
With the assistance of one of our esteemed Sales Engineers, Greg Kroon, let’s go through his simple and elegant example.
In this example, you will need to set up an AWS S3 Bucket to house our example NodeJS Lambda. Can come up with a creative name for the bucket.
After you create the S3 Bucket, you can upload Greg’s simple NodeJS function. Can download the zip from GitHub and upload it to your S3 bucket.
After the upload, we should get our Object URL, in my case “https://s3.amazonaws.com/harness.first.lambda.ravi/hello-world.zip”.
Since we are in AWS, if you do not have an Identity and Access Management [IAM] role to execute a Lambda either on the Harness Delegate or another existing role, you can create one ahead of time.
We can now create a new Harness Application, for example, My Lambda. Can create a new Application at Setup -> +Add Application.
Now inside the My Lambda Application, let’s create a Service called Lambda Service. Create the Lambda Service as an AWS Lambda Deployment Type. This can be found by going to Setup -> My Lambda -> Services
Once the Lambda Service has been created, we can go and define the Lambda Deployment Specification. For the example, set the target runtime as NodeJS 8.10 with a memory size of 128mb. We can also set the execution timeout to three seconds. For the function name, name the function “HelloWorld” and the handler to be “hello-world.handler”.
Next let’s add the artifact source as S3. Since we have already uploaded the artifact, we can simply link.
Now that we have our Lambda Service as a Harness Service, let’s make a Harness Environment to deploy to. Let’s create a non-prod Harness Environment. Can navigate to Environments by going to Setup -> My Lambda -> Environments
We can now wire the Service Infrastructure once we create the environment. Make sure to select the appropriate IAM Role and Region.
Now we can create a Harness Workflow encompassing our new Lambda. Can configure via Setup -> My Lambda -> Workflows. We will be creating a Basic Deployment Type. Select the Environment, Service, and Service Infrastructure.
When looking at our Basic Deployment Workflow, let’s add a Verification. Let’s look out for the payload with AWS Lambda Verification.
Next can add the AWS Lambda Verification with the payload of “{“status”:”OK”}”.
Now your Workflow should look like the following:
With our Workflow, let’s create a Pipeline to execute the Workflow.
Can setup a Harness Pipeline by going to Setup -> My Lambda -> Pipelines
We can wire in our Basic Deployment here.
A very simple one stage Pipeline!
Can start a new Harness Deployment off of the Pipeline. Navigate to Continous Deployment and Start New Deployment.
Once you hit Submit, the magic starts.
Success!
Look a new Lambda appeared!
Serverless and Harness — truly better together
Hope you enjoyed our three-part series on serverless. Now you are more dangerous in the serverless world can see the need for a robust pipeline. With Harness, you can instill confidence easily with a continuous delivery pipeline. Make sure to stay tuned to our Webinar that is coming up on Oct 4th where we will talk about all things serverless and check out our official documentation.
Cheers,
-Ravi