Skip to content

Commit 37b1858

Browse files
authored
feat: improve retry logic for AWS Lambda deployments (#25)
- Add a new cli flag `max-attempts` with default value 200 - Update `run` function to read `max-attempts` from the cli context - Replace `svc.WaitUntilFunctionUpdated` with `svc.WaitUntilFunctionUpdatedWithContext` - Use `request.WithWaiterMaxAttempts` to set max attempts in `Exec` function refer to: appleboy/lambda-action#58 hashicorp/packer#6569
1 parent 33fa341 commit 37b1858

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ func main() {
179179
Usage: "The function's X-Ray tracing configuration.",
180180
EnvVars: []string{"PLUGIN_TRACING_MODE", "TRACING_MODE", "INPUT_TRACING_MODE"},
181181
},
182+
&cli.IntFlag{
183+
Name: "max-attempts",
184+
Usage: "the maximum number of times the waiter should attempt to check the resource for the target state",
185+
EnvVars: []string{"PLUGIN_MAX_ATTEMPTS", "MAX_ATTEMPTS", "INPUT_MAX_ATTEMPTS"},
186+
Value: 200,
187+
},
182188
}
183189

184190
if err := app.Run(os.Args); err != nil {
@@ -216,6 +222,7 @@ func run(c *cli.Context) error {
216222
Description: c.String("description"),
217223
SessionToken: c.String("session-token"),
218224
TracingMode: c.String("tracing-mode"),
225+
MaxAttempts: c.Int("max-attempts"),
219226
},
220227
Commit: Commit{
221228
Sha: c.String("commit.sha"),

plugin.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/aws/aws-sdk-go/aws"
1111
"github.com/aws/aws-sdk-go/aws/awserr"
1212
"github.com/aws/aws-sdk-go/aws/credentials"
13+
"github.com/aws/aws-sdk-go/aws/request"
1314
"github.com/aws/aws-sdk-go/aws/session"
1415
"github.com/aws/aws-sdk-go/service/lambda"
1516
"github.com/gookit/goutil/dump"
@@ -46,6 +47,7 @@ type (
4647
Layers []string
4748
SessionToken string
4849
TracingMode string
50+
MaxAttempts int
4951
}
5052

5153
// Commit information.
@@ -224,9 +226,13 @@ func (p Plugin) Exec() error {
224226
svc := lambda.New(sess, config)
225227

226228
if isUpdateConfig {
227-
if err := svc.WaitUntilFunctionUpdated(&lambda.GetFunctionConfigurationInput{
228-
FunctionName: aws.String(p.Config.FunctionName),
229-
}); err != nil {
229+
if err := svc.WaitUntilFunctionUpdatedWithContext(
230+
aws.BackgroundContext(),
231+
&lambda.GetFunctionConfigurationInput{
232+
FunctionName: aws.String(p.Config.FunctionName),
233+
},
234+
request.WithWaiterMaxAttempts(p.Config.MaxAttempts),
235+
); err != nil {
230236
log.Println(err.Error())
231237
return err
232238
}

0 commit comments

Comments
 (0)