diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index f98de7260ae..42c4e01ab1a 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -27,6 +27,9 @@ func resourceAwsLambdaFunction() *schema.Resource { Read: resourceAwsLambdaFunctionRead, Update: resourceAwsLambdaFunctionUpdate, Delete: resourceAwsLambdaFunctionDelete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + }, Importer: &schema.ResourceImporter{ State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { @@ -392,11 +395,11 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e return nil }) if err != nil { - if !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") { + if !isResourceTimeoutError(err) && !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 { + // Allow additional time for slower uploads or EC2 throttling + err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { _, err := conn.CreateFunction(params) if err != nil { log.Printf("[DEBUG] Error creating Lambda Function: %s", err) diff --git a/aws/utils.go b/aws/utils.go index 21c3aab7ef3..b701ddbeadd 100644 --- a/aws/utils.go +++ b/aws/utils.go @@ -47,3 +47,8 @@ func isResourceNotFoundError(err error) bool { _, ok := err.(*resource.NotFoundError) return ok } + +func isResourceTimeoutError(err error) bool { + timeoutErr, ok := err.(*resource.TimeoutError) + return ok && timeoutErr.LastError == nil +} diff --git a/website/docs/r/lambda_function.html.markdown b/website/docs/r/lambda_function.html.markdown index e6b3d5d1b00..30651c5eed3 100644 --- a/website/docs/r/lambda_function.html.markdown +++ b/website/docs/r/lambda_function.html.markdown @@ -134,6 +134,12 @@ For **environment** the following attributes are supported: [8]: https://docs.aws.amazon.com/lambda/latest/dg/deployment-package-v2.html [9]: https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html +## Timeouts + +`aws_lambda_function` provides the following [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +* `create` - (Default `10m`) How long to wait for slow uploads or EC2 throttling errors. + ## Import Lambda Functions can be imported using the `function_name`, e.g.