Skip to content

Commit

Permalink
only retrieve credentials when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Jan 5, 2021
1 parent 852a23c commit 7f1ed12
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions x-pack/functionbeat/manager/aws/cli_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func (c *CLIManager) deployTemplate(update bool, name string) error {
}

c.log.Debugf("Using cloudformation template:\n%s", templateData.json)

_, err = c.awsCfg.Credentials.Retrieve()
if err != nil {
return fmt.Errorf("failed to retrieve aws credentials, please check AWS credential in config: %+v", err)
}

svcCF := cf.New(c.awsCfg)

executer := executor.NewExecutor(c.log)
Expand Down Expand Up @@ -144,6 +150,11 @@ func (c *CLIManager) Remove(name string) error {
c.log.Debugf("Removing function: %s", name)
defer c.log.Debugf("Removal of function '%s' complete", name)

_, err := c.awsCfg.Credentials.Retrieve()
if err != nil {
return fmt.Errorf("failed to retrieve aws credentials, please check AWS credential in config: %+v", err)
}

svc := cf.New(c.awsCfg)
executer := executor.NewExecutor(c.log)
executer.Add(newOpDeleteCloudFormation(c.log, svc, c.stackName(name)))
Expand Down Expand Up @@ -208,11 +219,6 @@ func NewCLI(
return nil, fmt.Errorf("failed to get aws credentials, please check AWS credential in config: %+v", err)
}

_, err = awsCfg.Credentials.Retrieve()
if err != nil {
return nil, fmt.Errorf("failed to retrieve aws credentials, please check AWS credential in config: %+v", err)
}

builder, err := provider.TemplateBuilder()
if err != nil {
return nil, err
Expand Down

0 comments on commit 7f1ed12

Please sign in to comment.