diff --git a/cmd/sst/mosaic/aws/function.go b/cmd/sst/mosaic/aws/function.go index afd838607a..3c2296e43f 100644 --- a/cmd/sst/mosaic/aws/function.go +++ b/cmd/sst/mosaic/aws/function.go @@ -189,7 +189,23 @@ func function(ctx context.Context, input input) { getBuildOutput := func(functionID string) *runtime.BuildOutput { build := builds[functionID] if build != nil { - return build + // check that the handler file still exists on disk + handlerFile := build.Handler + if i := strings.LastIndex(handlerFile, "."); i > 0 { + handlerFile = handlerFile[:i] + } + matches, _ := filepath.Glob(filepath.Join(build.Out, handlerFile+".*")) + if len(matches) == 0 { + // also check without extension for compiled binaries + if _, err := os.Stat(filepath.Join(build.Out, handlerFile)); err != nil { + log.Info("build output missing, rebuilding", "functionID", functionID, "handler", build.Handler) + delete(builds, functionID) + } else { + return build + } + } else { + return build + } } target, _ := targets[functionID] build, err := input.project.Runtime.Build(ctx, target) diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 72d8089a85..ad684a9b39 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -107,11 +107,14 @@ func (c *Collection) Build(ctx context.Context, input *BuildInput) (*BuildOutput } if input.Bundle == "" { - err := os.RemoveAll(out) - if err != nil { - return nil, err + // skip removing in dev mode so running workers don't lose their bundle files + if !input.Dev { + err := os.RemoveAll(out) + if err != nil { + return nil, err + } } - err = os.MkdirAll(out, 0755) + err := os.MkdirAll(out, 0755) if err != nil { return nil, err }