Search code examples
goaws-lambda-go

AWS Go Lambda: If/else Issue


I'm just trying to pick up Golang in the AWS Lambda flavor. I feel like the answer here is super simple, but I can't put my finger on it, nor could I find a post similar to this problem just yet.

//Lambda Function Go Code
package main
import "github.com/aws/aws-sdk-go"
import "github.com/aws/aws-lambda-go/lambda"
import "github.com/aws/aws-lambda-go/events"
import "errors"

func main() {
    lambda.Start(HandleRequest)
}

func HandleRequest(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    if request.HTTPMethod == "POST" {
        var stringResponse string = "Success :)"
        APIResponse := events.APIGatewayProxyResponse{Body: stringResponse, StatusCode: 200}
        return APIResponse, nil
    }
    else {
        err := errors.New("Method Not Allowed")
        APIResponse := events.APIGatewayProxyResponse{Body: "Method Not OK", StatusCode: 502}
        return APIResponse, err
    }
}

When I try saving and compiling this code, I get the following:

VSCode Go Windows 10

Can anyone tell me what exactly I'm doing run? I was writing in VSCode in Windows 10, but I feel this silly thing is not connected to that.


Solution

  • Your else needs to be inline with the } closing the if.