From b33d605cb0024b49938dca5987313309dfc3b142 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 27 Oct 2016 14:41:20 -0500 Subject: [PATCH] provider/aws: Limit AWS Lambda source uploads --- .../providers/aws/resource_aws_lambda_function.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/providers/aws/resource_aws_lambda_function.go b/builtin/providers/aws/resource_aws_lambda_function.go index 4fcc102b3..03db70170 100644 --- a/builtin/providers/aws/resource_aws_lambda_function.go +++ b/builtin/providers/aws/resource_aws_lambda_function.go @@ -17,6 +17,8 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) +const awsMutexLambdaKey = `aws_lambda_function` + func resourceAwsLambdaFunction() *schema.Resource { return &schema.Resource{ Create: resourceAwsLambdaFunctionCreate, @@ -154,6 +156,11 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e var functionCode *lambda.FunctionCode if v, ok := d.GetOk("filename"); ok { + // Grab an exclusive lock so that we're only reading one function into + // memory at a time. + // See https://github.com/hashicorp/terraform/issues/9364 + awsMutexKV.Lock(awsMutexLambdaKey) + defer awsMutexKV.Unlock(awsMutexLambdaKey) file, err := loadFileContent(v.(string)) if err != nil { return fmt.Errorf("Unable to load %q: %s", v.(string), err) @@ -361,6 +368,11 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e } if v, ok := d.GetOk("filename"); ok { + // Grab an exclusive lock so that we're only reading one function into + // memory at a time. + // See https://github.com/hashicorp/terraform/issues/9364 + awsMutexKV.Lock(awsMutexLambdaKey) + defer awsMutexKV.Unlock(awsMutexLambdaKey) file, err := loadFileContent(v.(string)) if err != nil { return fmt.Errorf("Unable to load %q: %s", v.(string), err)