provider/aws: more retrying with Lambda
This commit is contained in:
parent
89ca1bc86f
commit
6b733a09eb
|
@ -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 := conn.UpdateEventSourceMapping(params)
|
err := resource.Retry(1*time.Minute, func() error {
|
||||||
|
_, 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// IAM profiles can take ~10 seconds to propagate in AWS:
|
||||||
for i := 0; i < 5; i++ {
|
// 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(1*time.Minute, func() error {
|
||||||
_, err = conn.CreateFunction(params)
|
_, err = conn.CreateFunction(params)
|
||||||
if awsErr, ok := err.(awserr.Error); ok {
|
if err != nil {
|
||||||
|
if awserr, ok := err.(awserr.Error); ok {
|
||||||
// IAM profiles can take ~10 seconds to propagate in AWS:
|
if awserr.Code() == "InvalidParameterValueException" {
|
||||||
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
|
// Retryable
|
||||||
// Error creating Lambda function: InvalidParameterValueException: The role defined for the task cannot be assumed by Lambda.
|
return awserr
|
||||||
if awsErr.Code() == "InvalidParameterValueException" && strings.Contains(awsErr.Message(), "cannot be assumed by Lambda.") {
|
}
|
||||||
log.Printf("[DEBUG] Invalid IAM Instance Profile referenced, retrying...")
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
// Not retryable
|
||||||
|
return resource.RetryError{Err: err}
|
||||||
}
|
}
|
||||||
break
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue