Continuous Delivery for AWS Lambda Applications
Build your AWS Lambda pipelines with Harness Continuous Delivery. AWS Lambda is a web service you can use to build applications.
AWS Lambda is a web service you can use to build applications without having to worry about compute constraints or complexity. In order to use, simply upload your application code as Lambda functions and Lambda runs your code on high-availability compute infrastructure.
Lambda also performs all the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code and security patch deployment, and code monitoring and logging. All you need to do is supply your code in one of the languages that Lambda supports:
- Java (Java 8 compatible)
- C# (.NET Core)
Serverless - A Developer's Dream?
At the crux of it, Lambda is a developer's dream. No longer is there a requirement to set up infrastructure or configure servers. All that has to be done is simply deploy new code. Beyond ease of deployment, there are also monetary benefits.
Why run a server 24x7 that is just waiting to be hit by an API call that may or may not get called in the next half hour, hour, or even day? Why not simply pay for compute when your code is actually doing something? In comes Lambda!
Challenges With Continuous Delivery For Lambda
Immutable objects (those that can't be changed) have a few challenges when it comes to continuous delivery, thus so does Lambda. Lambda functions are versioned with the latest always being published to $LATEST. These versions are made up of both code as well as configuration (variables). Once the code and configuration are published, the function becomes immutable.
The challenge with continuous delivery on Lambda actually lies in the versioning, tagging(aliases), and rollbacks. Each new version is immutably pushed to $LATEST; as a result, rolling back to a previous version becomes complicated. This stands true even if your applications are properly designed to use tags. Moving forward is easy--it's reverting back that is complicated based on the previously successful tagged deployment.
At Harness, we solve that complexity by keeping track of the two pieces required to tag(alias) or recreate the function, the code, and the configuration. Harness not only works with the limitations of Lambda, but also implements the best practices for immutable infrastructure. Harness handles the burden of managing the code and config in order to properly version, tag, or recreate the previous version, thus allowing for fully automated rollbacks based on prescriptive failure strategies.
Deploying to AWS Lambda With Harness
Setting up Harness to manage the continuous delivery or continuous deployment of Lambda Functions was designed to not only be simple but also repeatable.
The process can be broken down into 5 easy steps:
1. Creating A New Lambda Service
Enter a Service name and select AWS Lambda as Artifact Type along with a brief description of the Service.
Next, add an Artifact Source. The example below shows Amazon S3 as the location.
Finally, add your Lambda Function Specifications (configuration).
2. Set Up Your Lambda Environment
Add Environment(s) with a name and an environment type (non-production/production):
Add Your Service Infrastructure by selecting the appropriate AWS account, region, IAM role, VPC, Subnets and Security Groups:
3. Creating Your Lambda Deployment Workflow
Workflows can be added individually for each Lambda Service deploying to each environment. You can also templatize these deployment workflows that can call Infrastructure, Service, and Environment as variables at runtime, removing the need for duplication across many Lambda services.
Harness will automatically populate the steps needed to deploy and rollback your Lambda Service:
You can also add workflow preparation, verification or wrap-up steps for your Lambda Service. In the example below, you can define simple test events for each of your Lambda functions using payload assertions.
At this point, the Workflow is ready to execute a workflow.
4. Creating your Lambda Pipeline
With Harness, you can stitch together multiple deployment workflows as pipeline stages across your development, QA, and production environments. These pipeline workflows and stages can either execute sequentially or in parallel depending on your needs. You can also templatize pipelines and delegate them to individual teams or users.
5. Build your Lambda Pipeline Trigger
Finally, triggers can be used to automatically execute pipelines based on new versions of Lambda Functions.
a. Define triggers to execute either a deployment Workflow or an entire Pipeline.
You're all done and ready to deploy!
Here's a quick two-minute video of deploying AWS Lambda using Harness: