Skip to content

Commit

Permalink
[AWS] Catch the appropriate error in aws.execution.ec2-launch-unusual…
Browse files Browse the repository at this point in the history
…-instances (closes #387) (#390)
  • Loading branch information
christophetd committed Jul 25, 2023
1 parent 7e125a0 commit 2c89c34
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ func detonate(params map[string]string, providers stratus.CloudProviders) error
return errors.New("expected ec2:RunInstances to return an error")
}

if !strings.Contains(err.Error(), "AccessDenied") {
// We expected an *AccessDenied* error
if !isExpectedError(err) {
return errors.New("expected ec2:RunInstances to return an access denied error, got instead: " + err.Error())
}

log.Println("Got an access denied error as expected")

return nil
}

func isExpectedError(err error) bool {
// We expected an *AccessDenied* or *UnauthorizedOperation* error
errorMessage := err.Error()
return strings.Contains(errorMessage, "AccessDenied") ||
strings.Contains(errorMessage, "UnauthorizedOperation")
}

0 comments on commit 2c89c34

Please sign in to comment.