provider/aws: more retrying with Lambda

This commit is contained in:
clint shryock 2016-01-05 11:22:57 -06:00
parent 89ca1bc86f
commit 6b733a09eb
2 changed files with 32 additions and 15 deletions

View File

@ -179,7 +179,22 @@ func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta inte
Enabled: aws.Bool(d.Get("enabled").(bool)), Enabled: aws.Bool(d.Get("enabled").(bool)),
} }
err := resource.Retry(1*time.Minute, func() error {
_, err := conn.UpdateEventSourceMapping(params) _, err := conn.UpdateEventSourceMapping(params)
if err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "InvalidParameterValueException" {
// Retryable
return awserr
}
}
// Not retryable
return resource.RetryError{Err: err}
}
// No error
return nil
})
if err != nil { if err != nil {
return fmt.Errorf("Error updating Lambda event source mapping: %s", err) return fmt.Errorf("Error updating Lambda event source mapping: %s", err)
} }

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"strings"
"time" "time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -15,6 +14,7 @@ import (
"errors" "errors"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -149,22 +149,24 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e
Timeout: aws.Int64(int64(d.Get("timeout").(int))), Timeout: aws.Int64(int64(d.Get("timeout").(int))),
} }
var err error
for i := 0; i < 5; i++ {
_, err = conn.CreateFunction(params)
if awsErr, ok := err.(awserr.Error); ok {
// IAM profiles can take ~10 seconds to propagate in AWS: // 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 // 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. // Error creating Lambda function: InvalidParameterValueException: The role defined for the task cannot be assumed by Lambda.
if awsErr.Code() == "InvalidParameterValueException" && strings.Contains(awsErr.Message(), "cannot be assumed by Lambda.") { err := resource.Retry(1*time.Minute, func() error {
log.Printf("[DEBUG] Invalid IAM Instance Profile referenced, retrying...") _, err = conn.CreateFunction(params)
time.Sleep(2 * time.Second) if err != nil {
continue if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "InvalidParameterValueException" {
// Retryable
return awserr
} }
} }
break // Not retryable
return resource.RetryError{Err: err}
} }
// No error
return nil
})
if err != nil { if err != nil {
return fmt.Errorf("Error creating Lambda function: %s", err) return fmt.Errorf("Error creating Lambda function: %s", err)
} }