In case you are eager about blockchain programming and need to leverage AWS Lambda for Web3, comply with alongside on this tutorial because it demonstrates how one can construct and deploy a Web3 AWS Lambda app in three easy steps:
- Protecting the Conditions
- Setting Up a New Challenge
- Growing the Lambda Utility
By masking the steps above, you’ll learn to create an AWS Lambda perform by integrating Moralis’ NodeJS SDK with the service. By finishing this Web3 AWS tutorial, it is possible for you to to run Web3 JavaScript code with Lambda, which you’ll be able to implement in all future blockchain initiatives!
If this sounds thrilling and also you need to get going instantly, you’ll be able to bounce into the tutorial by visiting the “AWS Web3 Tutorial” part under. What’s extra, you’ll be able to try the Web3 documentation web page for AWS Lambda and the whole GitHub repository for the applying down under:
Full Web3 AWS Lambda Documentation – https://github.com/MoralisWeb3/examples-aws-lambda-nodejs/tree/principal/aws-node-project
Overview
Are you interested by AWS and need to leverage Lambda to create refined Web3 initiatives? If that’s the case, be a part of us on this AWS Lambda tutorial, educating you how one can develop and deploy a Web3-ready Lambda utility with a number of capabilities. Particularly, you’ll learn to create capabilities for fetching the native token/NFT balances and working the code with AWS Lambda!
What’s extra, together with displaying you how one can create Lambda capabilities, this text additionally covers the intricacies of this service and what it means in a Web3 context. As such, we’ll discover how one can get AWS Web3 prepared by masking the very best AWS Web3 Lambda answer – Moralis! Nonetheless, if you would like a extra detailed breakdown, try our article on AWS Lambda and what it’s used for.

In case you are already acquainted with this service, you would possibly need to try extra content material right here at Moralis’ Web3 weblog. As an illustration, try our article answering the query, ”what’s GameSparks?”.
Nonetheless, earlier than transferring ahead, enroll with Moralis instantly since you will need to have an account to comply with alongside! What’s extra, with a Moralis account, you’ll be able to entry different instruments – corresponding to Moralis’ Web3 APIs – to completely leverage the facility of blockchain know-how!
AWS for Web3 – What’s AWS, Lambda, and Web3?
To adequately grasp what AWS and Lambda entail in a Web3 context, this preliminary part breaks down these three parts individually. As such, to start with, we’ll kick issues off by answering the next query: ”what’s AWS?”.
AWS is an abbreviation for ”Amazon Internet Providers”, and it’s the most intensive and adopted cloud platform worldwide. AWS presents greater than 200 companies, starting from infrastructure applied sciences, corresponding to database, storage, and compute options, to rising applied sciences like synthetic intelligence, machine studying, and so forth. By using AWS, you’ll be able to leverage the newest applied sciences to innovate and experiment at the next tempo, offering a major aggressive benefit, particularly in a fast-moving business like Web3.
Inside Amazon’s complete AWS ecosystem, you will discover Lambda, a serverless, event-driven computing service. With AWS Lambda, builders can run code with out having to fret about servers or clusters. All they should do is write and add code within the type of ”Lambda capabilities”, and the service takes care of the remaining!
Lambda capabilities are the spine of this service, and so they set off primarily based on occasions, that means Lambda solely invokes them when obligatory. Some outstanding examples embrace HTTP requests, an object modification in Amazon S3, a desk replace in DynamoDB, and so forth. Furthermore, since Lambda solely runs the capabilities when wanted, builders solely pay for the computing time the code consumes. As such, Lambda presents wonderful alternatives for scaling and value reductions.
That briefly covers AWS and Lambda; if you would like extra info on this service and the way it works, try our article explaining AWS Lambda capabilities and structure in additional element!
Nonetheless, now that you’ve familiarized your self with AWS Lambda, the next sub-section briefly introduces the ultimate part: Web3!
What’s Web3?
Web3 is, in layman’s phrases, extensively understood as the newest – and third – ”era” of the web. The preliminary ”section” or ”era” is often known as Web1. Throughout this section, customers primarily consumed and skim content material, suggesting that the expertise was comparatively static.
With the rise of outstanding social media conglomerates, the net shifted from static content material consumption to extra dynamic and interactive parts. As such, customers have been now not restricted to studying info however might contribute by creating content material themselves. Nonetheless, the Web2 revolution introduced vital points related to centralization, corresponding to putting massive portions of non-public knowledge within the palms of enormous companies and social media platforms. To unravel these points, we noticed the introduction of the web’s third era: Web3.
Web3 goals to maintain the optimistic dynamic facets of Web2 whereas concurrently eradicating the problems of centralization by making a decentralized web. As such, one of many main functions of Web3 is to create an web the place knowledge will not be owned by massive firms however reasonably shared amongst customers. This shift presents nice alternatives for rising and current corporations to say market share by innovating and disrupting typical enterprise fashions!
If you wish to learn extra about Web3 and the way it works, try the next article: ”The Final Information to Web3”.
Nonetheless, with a short introduction to AWS, Lambda, and Web3, the next part will clarify how one can get AWS Web3 prepared!
How one can Get AWS Web3 Prepared
Each AWS and Lambda are generally utilized in conventional Web2 growth to construct purposes, web sites, and different software program initiatives. Nonetheless, with the rise of Web3, blockchain builders at the moment are on the lookout for methods to simply get AWS Web3 prepared. In doing so, they’ll leverage outstanding companies like Lambda of their Web3 growth endeavors to create dapps faster and extra successfully!
Sadly, that is simpler stated than accomplished, which is why builders are in excessive demand for Web3 infrastructure suppliers like Moralis! Moralis gives enterprise-grade Web3 APIs and different instruments, making Web3 growth considerably extra accessible. What’s extra, because of the various integrations Moralis characteristic, you’ll be able to mix APIs, SDKs, and so forth., with different platforms like AWS!
Accordingly, one choice for getting AWS Web3 prepared is Moralis, and we elaborate additional on this within the following part, the place we discover the very best AWS Web3 Lambda answer!
The Greatest AWS Web3 Lambda Answer
In case you are seeking to develop Web3 initiatives and need to leverage AWS companies like Lambda, the simplest approach to take action is with the assistance of Moralis, as you’ll be able to rapidly combine Moralis’ NodeJS SDK with AWS Lambda!
By doing so, you’ll be able to run Web3-compatible JavaScript code via this AWS service. What’s extra, there are a number of methods in which you’ll be able to combine the NodeJS SDK, and two outstanding examples are by creating and deploying a Lambda utility or growing a Lambda NodeJS Categorical API. Nonetheless, by integrating the SDK, you’ll be able to leverage the options and advantages of Lambda, corresponding to computerized scaling and value reductions, which might show helpful in future growth endeavors!
If this sounds thrilling and also you need to study extra about integrating Moralis’ NodeJS SDK with AWS Lambda, comply with within the subsequent part, the place we cowl an AWS Lambda Web3 tutorial in additional element!
AWS Web3 Tutorial
Now that you’re extra acquainted with AWS Lambda and why you would possibly need to leverage this service in Web3 growth, this half covers a complete AWS Lambda Web3 tutorial. Moreover, the next sections will present you how one can combine Moralis’ NodeJS SDK with Lambda, permitting you to run Web3 JavaScript capabilities via this AWS service. For instance the method, we can be growing and deploying a Lambda utility with two capabilities: ”getNativeBalance()” and ”getWalletNfts()”.

Furthermore, because of the accessibility of Moralis’ Lambda integration, you’ll be able to create this utility and get AWS Web3 prepared in solely three steps:
- Protecting the Conditions
- Setting Up a New Challenge
- Growing the Lambda Utility
So, with out additional ado, let’s kick issues off by masking the required conditions!
Step 1: Protecting the Conditions
To create this AWS Lambda app with a number of capabilities, you’ll want to cowl the next seven conditions:
- Create a Moralis account
- Set up an built-in growth atmosphere (IDE)
- Arrange an AWS account
- Set up NodeJS
- Arrange the AWS CLI
- Set up Serverless Framework
- Create an IAM Consumer
Most conditions are simple and will be handled utilizing the hyperlinks above. Nonetheless, there are some things you’ll want to think about when creating the IAM consumer. To create the consumer, log in to AWS’ Administration Console and open the IAM console. You then must click on on ”Customers” and ”Add customers” within the navigation bar. Consequently, it ought to take you to the next web page:
When you arrive on the web page above, add a username and ensure to incorporate each credential sorts. When transferring on to the second half, verify the field for ”AdministratorAccess”:
Lastly, cowl the remaining steps till you attain the final one, the place you’ll want to be sure that you obtain your AWS credentials in a ”.csv” file:
Step 2: Setting Up a New Challenge
On this second step, we’ll present you how one can arrange the mission. Nonetheless, earlier than doing so, you’ll want to configure your AWS credentials. As such, open your IDE, launch a brand new terminal, and run the next command:
aws configure
When you run the command above, it’ll immediate you to enter your ”AWS Secret Entry Key”. Following this, you will need to add your ”AWS Entry Key ID”. Lastly, there can be two remaining prompts, for which you solely must hit ”enter”. All in all, it ought to look one thing like this:
AWS Entry Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Entry Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default area title [None]: ENTER Default output format [None]: ENTER
Challenge Setup
With the AWS credential configurations full, we’ll now present you how one can arrange the mission. To start with, create a brand new folder. Then, open it together with your IDE, and run the next command in a brand new terminal:
serverless
This may set off your terminal, and you will need to make a couple of choices. For the primary query, choose the ”Starter” choice:
Subsequent up, title your mission by inputting a reputation or instantly hit ”enter”:
Whenever you title the mission, it can autonomously obtain a brand new Serverless Framework template. As soon as it completes, the terminal will ask you to log in. For now, you’ll be able to skip this by inputting ”n” and hitting ”enter”:
From there, you’ll be requested if you wish to deploy the mission. You’ll be able to put this off for now by as soon as once more inputting ”n” and hitting “enter”:
Consequently, you need to now have a pattern mission in your native listing wanting one thing like this:
Subsequent up, add a brand new folder referred to as ”capabilities”:
You’ll be able to then go forward and transfer the ”handler.js” file into this folder:
Lastly, open the ”serverless.yml” file and substitute the contents with the code from the snippet under:
service: aws-node-project frameworkVersion: '3' supplier: title: aws runtime: nodejs14.x atmosphere: MORALIS_API_KEY: 'replace_me' capabilities: hiya: handler: capabilities/handler.hiya
Moreover, discover that you’ll want to add your Moralis API key by changing ”replace_me” throughout the code. You’ll be able to purchase the important thing by logging into Moralis and clicking on the ”Web3 APIs” tab:
Step 3: Growing the Lambda Utility
This part exhibits you how one can add the 2 capabilities of the applying. Nonetheless, earlier than doing so, you’ll want to set up Moralis dependencies. As such, ”cd” into the mission’s root folder and run the command under within the terminal:
npm set up moralis
With the dependencies put in, we’ll progress by displaying you how one can add the ”getNativeBalance()” perform. That perform fetches the native steadiness of a Web3 pockets. Moreover, we’ll additionally add the ”getWalletNfts()” perform, which does the identical for NFTs:
- ”getNativeBalance()” – To start with, rename the present ”handler.js” file to ”getNativeBalance.js”:
From there, open ”serverless.yml” and alter the perform handler and title:
Lastly, copy the code from the snippet under and substitute all the things throughout the ”getNativeBalance.js” file:
'use strict'; const Moralis = require('moralis').default; const startMoralis = async () => { await Moralis.begin({ apiKey: course of.env.MORALIS_API_KEY }); }; startMoralis(); module.exports.handler = async (occasion) => { // Get native steadiness const nativeBalance = await Moralis.EvmApi.steadiness.getNativeBalance({ tackle: occasion.tackle, chain: occasion.chain }); // Format the native steadiness formatted in ether by way of the “.ether” getter const nativeBalanceEther = nativeBalance.end result.steadiness.ether; return { end result: nativeBalanceEther } };
- ”getWalletNfts()” – So as to add this perform, begin by creating a brand new file referred to as ”getWalletNfts.js”:
You’ll be able to then open ”serverless.yml” and enter the code under into the ”capabilities” part:
getWalletNfts: handler: capabilities/getWalletNfts.handler
Lastly, open ”getWalletNfts.js” and add the code from the next snippet:
'use strict'; const Moralis = require('moralis').default; const startMoralis = async () => { await Moralis.begin({ apiKey: course of.env.MORALIS_API_KEY, }); }; startMoralis(); module.exports.handler = async (occasion) => { // Get pockets NFTs const nfts = await Moralis.EvmApi.nft.getWalletNFTs({ tackle: occasion.tackle, chain: occasion.chain, restrict: 10 }); return { end result: JSON.stringify(nfts) } };
Now that covers the 2 capabilities and the whole thing of the Lambda utility. From right here, all that continues to be is to check and deploy the applying to AWS. As such, we’ll take the final part to point out you the way to take action!
Testing and Deploying the Utility
Allow us to begin by testing the capabilities to make sure all the things works as meant. As such, progress by creating a brand new file referred to as ”occasion.json” within the mission’s root folder:
From there, you’ll want to add two parameters to this file, ”tackle” and ”chain”:
{ "tackle": "0x99EXAMPLEADDRESS", "chain": "chain_id" }
Nonetheless, ensure you add the tackle of the pockets you need to monitor and the chain ID of the blockchain you need to question. With the parameters added, you’ll be able to take a look at every perform. To take action, run the command under and swap ”FUNCTION_NAME” with the perform’s precise title:
serverless invoke -f “FUNCTION_NAME” --path occasion.json
If you happen to take a look at ”getNativeBalance()”, it ought to return the next message if all the things works as meant:
As soon as you might be pleased with the outcomes, you’ll be able to deploy them by navigating to the foundation folder of the applying in your terminal and working the next command:
serverless deploy
When the app efficiently deploys, you need to be introduced with the next output in your terminal:
That’s it for this AWS Lambda NodeJS tutorial! You now know how one can create and deploy an AWS Lambda perform! Nonetheless, should you skilled hassle at any level throughout this tutorial, try the Web3 documentation web page for AWS Lambda. The documentation ought to hopefully reply any of your queries!
Web3 AWS Lambda – Abstract
On this article, you discovered how one can combine Moralis’ NodeJS SKD with AWS. Moreover, you probably did so by making a Lambda utility with a number of capabilities. What’s extra, because of the capabilities of Moralis, you have been in a position to get AWS Web3 prepared in solely three steps:
- Protecting the Conditions
- Setting Up a New Challenge
- Growing the Lambda Utility
As such, you probably have adopted alongside this far, you now know how one can run Web3 JavaScript code with AWS Lambda. Consequently, now you can leverage the advantages of this service, corresponding to reducing prices and never having to fret about managing servers!
If you happen to discovered this text useful, think about testing extra Moralis guides. As an illustration, you is likely to be eager about our article exploring the last word ERC20 token API. Additionally, be certain that to learn our information on how one can use Polygon webhooks!
Nonetheless, it doesn’t matter what Web3 growth endeavor you embark on, enroll with Moralis right away. You’ll be able to create your account totally free, and it solely takes a few seconds!