Aws-sam-cli: Hot reloading not working for go lambdas?

Created on 6 Apr 2018  路  8Comments  路  Source: aws/aws-sam-cli

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
arelambda-invoke typfeature

Most helpful comment

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

All 8 comments

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!

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

:+1:

馃憤

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.

@bernardobelchior Exactly.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

red8888 picture red8888  路  3Comments

zhangzhx picture zhangzhx  路  3Comments

jpbarto picture jpbarto  路  4Comments

joekiller picture joekiller  路  4Comments

GerbenRampaart picture GerbenRampaart  路  3Comments