Skip to Content
All memories

GOLANG get parameters from aws APIGateway using aws lambda functions

 — #AWS

Before, move to titorial please, setup your aws lambda and aws APIDateway. Let's start,

  • Create main.go file and paste the below code.
package main

import (


type MyResponse struct {
	Name string `json:"name:"`
	Firstname string `json:"firstname:"`
	Lastname string `json:"lastname:"`

func HandleRequest(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	if request.HTTPMethod == "GET" {
		firstname := request.QueryStringParameters["firstname"]
		lastname := request.QueryStringParameters["lastname"]
		Name := firstname + lastname

		Response := MyResponse{Name, firstname, lastname}
		var jsonData []byte
		jsonData, err := json.Marshal(Response)
		if err != nil {

		ApiResponse := events.APIGatewayProxyResponse{Body: string(jsonData), StatusCode: 200}
		return ApiResponse, nil
	} else {
		err := errors.New("Method not allowed")
		ApiResponse := events.APIGatewayProxyResponse{Body: "Method Not OK", StatusCode: 502}
		return ApiResponse, err

func main() {
  • Go mod initialize and get required libraries.
go mod init main
go get
go get
  • Build and zip main file for upload to aws lambda. Here, I mentioned the code for windows.
go build -o main main.go
tar.exe -a -c -f main