Categorygithub.com/Kitaministrator/api-proxy-lambda
modulepackage
1.0.0
Repository: https://github.com/kitaministrator/api-proxy-lambda.git
Documentation: pkg.go.dev

# 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:

  1. 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.

  2. Log in to the AWS Console.

  3. Select a region from the top right corner. Choose a region that balances latency and cost.

  4. In the search bar located in the upper left corner, enter "Lambda" and navigate to the Lambda service page.

  5. On the left-side panel, select "Functions", then click the "Create function" button on the following page.

  6. Select "Author from scratch".

  7. Enter a function name, such as "api-proxy", select "Go 1.x" runtime, and choose "x86_64" architecture.

  8. Leave the other settings as default and click "Create function".

  9. 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.

  10. 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.

  11. On the "Configuration" tab, select "Environment variables" on the left side panel. Add the following two environment variables:

KeyValue
DEST_DOMAINhttps://api.somewhere.com/
LOG_MODEtrue

Click "Save" to finish this page.

  1. 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.

  2. 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".

  3. 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".

  4. 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.

  1. 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

  2. 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.

# Functions

No description provided by the author

# Structs

No description provided by the author

# Type aliases

No description provided by the author