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: Handle slower code uploads on creation with configurable timeout #6409

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions aws/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions website/docs/r/lambda_function.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down