Skip to content

Commit

Permalink
Wait until the function code has been successfully updated
Browse files Browse the repository at this point in the history
Fixes #313

The current implementation does not wait LastUpdateStatus to be
Successful after UpdateFunctionCodeWithContext call. This might not
matter with small zip packages, but it does matter with large container
images.
  • Loading branch information
minamijoyo committed Sep 21, 2023
1 parent 38b3fc1 commit 417d61c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ func (app *App) updateFunctionCode(ctx context.Context, in *lambda.UpdateFunctio
return nil, err
}

var res *lambda.FunctionConfiguration
retrier := retryPolicy.Start(ctx)
for retrier.Continue() {
res, err := app.lambda.UpdateFunctionCodeWithContext(ctx, in)
var err error
res, err = app.lambda.UpdateFunctionCodeWithContext(ctx, in)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
Expand All @@ -226,10 +228,20 @@ func (app *App) updateFunctionCode(ctx context.Context, in *lambda.UpdateFunctio
}
return nil, errors.Wrap(err, "failed to update function code")
}
log.Println("[info] updated function code successfully")
return res, nil
log.Println("[info] update function code request was accepted")
break
}
return nil, errors.New("failed to update function code (max retries reached)")

if !retrier.Continue() {
return nil, errors.New("failed to update function code (max retries reached)")
}

if err := app.waitForLastUpdateStatusSuccessful(ctx, *in.FunctionName); err != nil {
return nil, err
}
log.Println("[info] updated function code successfully")

return res, nil
}

func (app *App) waitForLastUpdateStatusSuccessful(ctx context.Context, name string) error {
Expand Down

0 comments on commit 417d61c

Please # to comment.