This content originally appeared on DEV Community and was authored by Pavan Belagatti
Welcome to this tutorial on how to deploy a serverless Lambda application! Serverless architecture has become increasingly popular over the years due to its many benefits such as cost-effectiveness, scalability, and reduced infrastructure management. Amazon Web Services (AWS) Lambda is a popular serverless platform that allows you to run code without provisioning or managing servers. In this tutorial, you will learn how to deploy a serverless Lambda application step-by-step.
Let's get started!
Prerequisites:
- Free Harness CD module to deploy the serverless application
- Fork this serverless Node.js repo example, this is what we are going to deploy.
- A Kubernetes cluster access. Let's use Minikube in this tutorial.
- Harness Delegate with Serverless installed: the Harness Delegate is a worker process that performs all deployment tasks. Don't worry about this, I'll show you how to do it.
- AWS User account with required policy: Serverless deployments require an AWS User with specific AWS permissions, as described in AWS Credentials from Serverless.com.
To create the AWS User, do the following:
Log into your AWS account and go to the Identity & Access Management (IAM) page.
Click Users, and then Add user. Enter a name. Enable Programmatic access by clicking the checkbox. Click Next to go to the Permissions page.
Full Admin Access: click on Attach existing policies directly. Search for and select AdministratorAccess then click Next: Review. Check to make sure everything looks good and click Create user.
View and copy the API Key and Secret to a temporary place. You'll need them later in the tutorial.
Tutorial:
Login to the Harness CD module. Harness is a modern continuous delivery platform with AI/ML capabilities that helps to deploy applications faster.
Invite collaborators in you want to your project
From the side bar, click on pipelines and start creating your CD pipeline.
Next select the deploy stage and add the details
Select the serverless lambda deployment type from the deployment options available.
Next, create a service to deploy.
Add the serverless manifest details
Since our serverless manifest file is stored in GitHub let's add these details.
The details we are specifying for our serverless application repo you forked above.
Add your GitHub username and password. Add password through a secret manager.
Now, it is time to connect our GitHub repo to the Harness delegate.
But we don't have any delegate yet ready, let's create one.
Create install new delegate and you will land to this next page where you will be guided to install your delegate.
Select Kubernetes manifest and basic from the options.
Download the delegate yml file and edit it, why? Because we need to make sure it handles our serverless commands.
Open your delegate yml file just downloaded and edit it and add the following command in the place of init_script
- name: INIT_SCRIPT
value: |-
microdnf install -y nodejs
npm install -g serverless@2.50.0
See the screenshot for more clear understanding.
Save the yml file.
Make sure a cluster is running on your local to install the delegate. We can use Minikube to create a single node cluster and install our delegate.
Start the minikube with the following command
minikube start
Apply the following kubectl command for the yml.
kubectl apply -f harness-delegate.yml
Once you apply the above command, you can see a bunch of configurations getting added.
You can verify the delegate installation
Once you successfully install the delegate, you will get back to the delegate connection step. Now, you will see the newly added valid delegate in the list to connect our manifest.
Make sure the connection is successful.
Continue adding your manifest details.
Now you can see your added manifest details in the service details.
Next, create a pre-prod environment and connect AWS infrastructure.
Connect AWS in the infrastructure, and make sure you have the required details from your AWS account.
You need to connect your AWS connector with Harness delegate.
In the deployment step, you will select the rolling deployment step.
Save everything and run the pipeline.
You will see a successful lambda deployment.
For more understanding, follow this official Harness developer hub guide.
This content originally appeared on DEV Community and was authored by Pavan Belagatti
Pavan Belagatti | Sciencx (2023-05-02T05:03:19+00:00) Deploying Your First Serverless Lambda Application: A Beginner’s Tutorial. Retrieved from https://www.scien.cx/2023/05/02/deploying-your-first-serverless-lambda-application-a-beginners-tutorial/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.