In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The serverless service model (Serverless) in AWS is a hot technology in the past two years, which allows services to execute code when needed without any server configuration.
Let's take a look at a simple example of how to implement a basic serverless architecture through cloud services such as Lambda,API Gateway and S3.
Example 1: click a button on a web page to update the content of the web page.
To briefly explain the process, the user visits a static website on S3, clicks a button, performs a Get operation of javascript's AJAX, and calls Amazon API Gateway, which Gateway calls the corresponding Lambda function to return the result to the web page.
First let's create a new Lambda function
Select high-level language and IAM Role
After the creation of the interface, the function name is displayed in the middle, and then the resources that he can access are displayed next to it.
Then we enter our own code, which is very simple and returns a value in JSON format.
Then add a trigger, here select API Gateway
Select New API
Then you can click on the name of API to enter the configuration interface of API Gateway. His default Action is Any. Delete it and create a new Action for Get
Create a new method of Get and bind our functions
Process diagram
Going back to the interface of Lambda, you can see the automatically generated API Endpoint. Visit him directly and you can call our function.
Next, we need to create a bucket for S3, not to mention the details. After building it, choose to build a static website and upload our index.html and error.html
Here is the content of our index.html. When the button is clicked, it executes the method of javascript and then performs a GET operation of AJAX to get the return value from the specified API Gateway.
Function myFunction () {var xhttp = new XMLHttpRequest (); xhttp.onreadystatechange = function () {if (this.readyState = = 4 & & this.status = = 200) {document.getElementById ("my-demo") [xss_clean] = this.responseText;}} Xhttp.open ("GET", "https://br6b44zf93.execute-api.ap-southeast-2.amazonaws.com/default/Demo1", true); xhttp.send ();}
Hello Guys!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.