Skip to content

Commit

Permalink
Merge pull request #314 from minamijoyo/wait-until-function-code-updated
Browse files Browse the repository at this point in the history
Wait until the function code has been successfully updated
  • Loading branch information
fujiwara authored Sep 22, 2023
2 parents 38b3fc1 + 417d61c commit cc75712
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 cc75712

Please # to comment.