serverless makes an interface for querying IP addresses

serverless makes an interface for querying IP addresses

Briefly introduce:

Serverless Framework : Serverless Framework is a very popular serverless application framework in the industry. Developers can deploy a complete and usable serverless application framework without caring about the underlying resources.

Tool preparation:

First make sure that the system contains the following environment:

1. Install Node.js and npm

Check whether the machine is installed through the node -v command. If it is not installed, refer to the node.js installation guide to install according to the computer system environment

2. Install Serverless Framework

npm install -g serverless//Global Serverless Framework CLI

serverless -v//View the version information of the Serverless Framework CLI

3. Create Serverless service

serverless create -t ‚Äč‚Äčtencent-nodejs -p get_ip 
cd get_ip//Enter the get_ip directory
npm install//install dependencies 

4. Modify the return value in the index.js file

'use strict';

exports.main_handler = (event, context, callback) => {
  return event["requestContext"]["sourceIp"]

5. Configure the serverless.yml file

service: get-ip

provider: # provider information
  name: tencent
  runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
  credentials: ~/credentials


    handler: index.main_handler
         name: hello_world_apigw
           stageName: release
           httpMethod: ANY

6. Deployment

serverless deploy

Will pop up when you deploy a two-dimensional code, which is used to log Tencent cloud account , the micro-channel scan code can register, login, authorized the deployment of

After the deployment is successful, open the ANY access path above, and you can see your IP

Reference: serverless to make an interface for querying IP addresses-Cloud + Community-Tencent Cloud