# README
api-proxy-lambda
An API proxy designed for AWS serverless architecture, works with Lambda and API Gateway.
User Manual
Requirements:
- An Amazon Web Service account
- A web browser
Steps:
-
Download the release file or compile the source code to a binary file with the following environment variables set:
$env:GOOS = "linux" $env:GOARCH = "amd64" $env:CGO_ENABLED = "0"`
Then compress the binary file into a .zip file.
-
Log in to the AWS Console.
-
Select a region from the top right corner. Choose a region that balances latency and cost.
-
In the search bar located in the upper left corner, enter "Lambda" and navigate to the Lambda service page.
-
On the left-side panel, select "Functions", then click the "Create function" button on the following page.
-
Select "Author from scratch".
-
Enter a function name, such as "api-proxy", select "Go 1.x" runtime, and choose "x86_64" architecture.
-
Leave the other settings as default and click "Create function".
-
On the "api-proxy" function page, scroll down to the "Code" tab. Click "Upload from" - ".zip file" on the right, upload the compressed file, and wait for it to become ready.
-
Click "Add trigger". On next page, select "API Gateway" and "Create a new API". Choose "HTTP API" for API type and "Open" for security. Click "Add" to finish this page.
-
On the "Configuration" tab, select "Environment variables" on the left side panel. Add the following two environment variables:
Key | Value |
---|---|
DEST_DOMAIN | https://api.somewhere.com/ |
LOG_MODE | true |
Click "Save" to finish this page.
-
Using the search bar again, navigate to the API Gateway page. You'll see the API created by Lambda, which may have a default name "api-proxy-API". Click to enter its detail page.
-
In the "Detail" page, click "Routes" on the left side. You can see a default route leading all incoming traffic from the exact path "/api-proxy".
-
Since we're making a domain redirection, we'll use a greedy path variable. Click "Create" and enter "/api-proxy/{proxy+}" in the textbox. Leave the drop-down list on "ANY" and click "Create".
-
Click "Integrations" on the left. You will see a tree view like this:
├── /api-proxy │ ANY AWS Lambda │ └── /{proxy+} ANY
As you can see, there's nothing attached to the "/{proxy+}" path, which means this path won't do anything for now. Click on the "ANY" below the "/{proxy+}" path. Select "api-proxy" from the drop-down list on the right panel, then click "Attach integration" to finish.
-
Your API Gateway and Lambda function should work now. Send an HTTP request to the API Gateway's Invoke URL with the function path, which might be like: https://random-characters.execute-api.your-region.amazonaws.com/default/api-proxy/and-whatever-you-want-to-add
And this application will redirect your request to: https://api.somewhere.com/and-whatever-you-want-to-add
-
The logs can be found in CloudWatch services under "Logs" - "Log groups" with a default name "/aws/lambda/api-proxy", after your first log generated by calling the API or test in Lambda function page.