aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Hot reloading not working for go lambdas? #353

Closed uccmen closed 4 years ago

uccmen commented 6 years ago

Is it just me or hot-reloading doesn't work for lambdas written in golang?

cmd

aws-sam-local local start-api

hello/main.go

package main

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

type Response struct {
    Message string `json:"message"`
}

func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    return events.APIGatewayProxyResponse{
        Body:       "Go Serverless v1.0! Your function executed successfully!",
        StatusCode: 200,
    }, nil
}
func main() {
    lambda.Start(Handler)
}

template.yml

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A hello world application.
Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: bin/hello
      Runtime: go1.x
      Events:
        Vote:
          Type: Api
          Properties:
            Path: /hello
            Method: get
mijdavis2 commented 6 years ago

As golang is a compiled language, hot reloading is not (yet?) supported:

If you use an interpreted language, local changes are made available within the same Docker container. This approach means you can reinvoke your Lambda function with no need for redeployment. source

That being said - ๐Ÿ‘for this feature!

uccmen commented 6 years ago

thanks @mijdavis2, I implemented a workaround (in the meantime) for hot reload to work when developing Go lambdas locally - https://github.com/uccmen/serverless-go

Szasza commented 6 years ago

:+1:

debnath commented 6 years ago

๐Ÿ‘

bernardobelchior commented 5 years ago

aws-sam-cli mounts the CodeUri directory and run the handler with the name Handler in Docker. As such, you could (with a separate tool) watch the Go code for changes and build it. Because the CodeUri is mounted, the recompiled version would be "visible" to the Docker container and you can run the new version without restarting the aws-sam-cli.

ghost commented 5 years ago

@bernardobelchior Exactly.

I use https://github.com/cespare/reflex to watch and build

terrywarwar commented 4 years ago

When running local start-api could you build the invoked function defined in CodeUri before mounting to Docker . Running sam build every time is slow when you have large number of functions defined.

jfuss commented 4 years ago

@uccmen We do support hot-reloading of each language. The term hot-reloading to us means we will always mount the CodeUri on the next invoke. This allows you to stand up one api locally, and change/build your code outside that process to be reflected on the next invoke.

Closing this as we currently support it, but if we have a misunderstanding please reopen or create a new issue.