25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Creating our First Endpoint

December 28, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

cmd/health/main.go
package main

import (
	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
)

func Handler(request events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) {
	return events.APIGatewayProxyResponse{
		Body:       "I'm Alive",
		StatusCode: 200,
	}, nil
}

func main() {
	lambda.Start(Handler)
}
import * as sst from "@serverless-stack/resources";

export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // Create a HTTP API
    const api = new sst.Api(this, "Api", {
      routes: {
        "GET /api/health": "cmd/health"
      }
    });

    // Show the endpoint in the output
    this.addOutputs({
      "ApiEndpoint": api.url,
    });
  }
}
$ npx run start
$ curl https://9d27htf1fk.execute-api.us-east-1.amazonaws.com/
Hello, World! Your request was received at 25/Oct/2021:17:48:38 +0000.%