Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_lambda_function: Only retry IAM errors for one minute #3765

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,8 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e
params.Tags = tagsFromMapGeneric(v.(map[string]interface{}))
}

// IAM profiles can take ~10 seconds to propagate in AWS:
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
// Error creating Lambda function: InvalidParameterValueException: The role defined for the task cannot be assumed by Lambda.
err := resource.Retry(10*time.Minute, func() *resource.RetryError {
// IAM changes can take 1 minute to propagate in AWS
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.CreateFunction(params)
if err != nil {
log.Printf("[DEBUG] Error creating Lambda Function: %s", err)
Expand All @@ -386,7 +384,27 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e
return nil
})
if err != nil {
return fmt.Errorf("Error creating Lambda function: %s", err)
if !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
return fmt.Errorf("Error creating Lambda function: %s", err)
}
// Allow 9 more minutes for EC2 throttling
err := resource.Retry(9*time.Minute, func() *resource.RetryError {
_, err := conn.CreateFunction(params)
if err != nil {
log.Printf("[DEBUG] Error creating Lambda Function: %s", err)

if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
log.Printf("[DEBUG] Received %s, retrying CreateFunction", err)
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error creating Lambda function: %s", err)
}
}

d.SetId(d.Get("function_name").(string))
Expand Down Expand Up @@ -686,7 +704,8 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
if configUpdate {
log.Printf("[DEBUG] Send Update Lambda Function Configuration request: %#v", configReq)

err := resource.Retry(10*time.Minute, func() *resource.RetryError {
// IAM changes can take 1 minute to propagate in AWS
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateFunctionConfiguration(configReq)
if err != nil {
log.Printf("[DEBUG] Received error modifying Lambda Function Configuration %s: %s", d.Id(), err)
Expand All @@ -704,7 +723,26 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
return nil
})
if err != nil {
return fmt.Errorf("Error modifying Lambda Function Configuration %s: %s", d.Id(), err)
if !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2, please make sure you have enough API rate limit.") {
return fmt.Errorf("Error modifying Lambda Function Configuration %s: %s", d.Id(), err)
}
// Allow 9 more minutes for EC2 throttling
err := resource.Retry(9*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateFunctionConfiguration(configReq)
if err != nil {
log.Printf("[DEBUG] Received error modifying Lambda Function Configuration %s: %s", d.Id(), err)

if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2, please make sure you have enough API rate limit.") {
log.Printf("[DEBUG] Received %s, retrying UpdateFunctionConfiguration", err)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error modifying Lambda Function Configuration %s: %s", d.Id(), err)
}
}

d.SetPartial("description")
Expand Down