Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait until update finishes before deploying an image #65

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Wait until update finishes before deploying an image
  • Loading branch information
zhihaoy committed Feb 17, 2023
commit a0fe7c245e17c80732f29951613e66eb987ecab2
14 changes: 9 additions & 5 deletions cmd/llama/internal/function/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func createOrUpdateFunction(ctx context.Context, g *cli.GlobalState, cfg *functi

_, err := client.CreateFunction(args)
if err == nil {
return waitForFunction(ctx, client, cfg)
return waitForFunction(ctx, client, cfg, "Creating")
}
if reqerr, ok := err.(awserr.RequestFailure); ok && reqerr.StatusCode() == 409 {
return updateFunction(ctx, g, cfg)
Expand Down Expand Up @@ -95,6 +95,9 @@ func updateFunction(ctx context.Context, g *cli.GlobalState, cfg *functionConfig
if _, err := client.UpdateFunctionConfiguration(args); err != nil {
return err
}
if err := waitForFunction(ctx, client, cfg, "Updating"); err != nil {
return err
}

if cfg.tag != "" {
codeArgs := &lambda.UpdateFunctionCodeInput{
Expand All @@ -104,14 +107,15 @@ func updateFunction(ctx context.Context, g *cli.GlobalState, cfg *functionConfig
if _, err := client.UpdateFunctionCode(codeArgs); err != nil {
return err
}

return waitForFunction(ctx, client, cfg, "Deploying")
}
return waitForFunction(ctx, client, cfg)

return nil
}

func waitForFunction(ctx context.Context, client *lambda.Lambda, config *functionConfig) error {
func waitForFunction(ctx context.Context, client *lambda.Lambda, config *functionConfig, prompt string) error {
args := &lambda.GetFunctionInput{FunctionName: &config.name}
log.Printf("Update complete, waiting for function %s...", config.name)
log.Printf("%s function %s...", prompt, config.name)
for {
time.Sleep(3 * time.Second)
out, err := client.GetFunction(args)
Expand Down