Requirements: Create a gateway on AWS and then use Lambda to add authentication capabilities.
Log in to the AWS console, select the appropriate region according to your situation, and then create an HTTP API gateway as shown in the following figure:
Start a name, then keep next (or directly review and create), set other configurations later, and click Create in the last step, as shown in the figure below:
Below create a route /bbs reverse proxy to this website, fill it out“/bbs/{proxy+}”, the routing method can be selected ANY, which allows all HTTP methods, as shown in the figure below:
After creating the route, select the path and click the Attach Integration button on the right, as shown in the image below:
Select Create and attach an integration as shown in the following image:
Integration type type Select HTTP URI, and fill in the specific reverse proxy URL (https://www.itsvse.com/{proxy}), and finally click Create, as shown below:
Click on the API to view the endpoint address and use postman to test as shown below:
If you don't want to access it publicly, you need to set up Authorization, find the Lambda menu from the AWS backend, and create a function as shown in the figure below:
Give it a name: demo-authentication, select :node.js 22.x version at runtime, choose arm64 for the architecture (the price will be cheaper), and finally click create function, as shown below:
The editor code is as follows:
Click the deploy button on the left, as shown below:
To set the lambda environment variables, click Configuration -> Environment variables -> Edit, as shown in the following figure:
Back to the API Gateway dashboard, select Authorization and click create as shown in the following figure:
Select Attach authorizers to routes to add existing authentications, as shown in the following image:
Try using the postman request interface again and return a 401 status and an error message (Unauthorized), as shown in the figure below:
When we add Authorization information to the request header, the request can be successful, as shown in the figure below:
Reference:
The hyperlink login is visible.
The hyperlink login is visible.
(End)
|