title: AWS S3 Error occurred while GetObject. S3 Error Code: NoSuchKey with Terraform
body: <p>I'm getting <code>Error occurred while GetObject. S3 Error Code: NoSuchKey</code> even though I've created a bucket, is there a wait time to use the key after creating the bucket?</p>
  <p>Here's my terraform script</p>
  <pre><code>resource &quot;aws_s3_bucket&quot; &quot;lambda_fn_upload&quot; {
    bucket = var.bucket
    acl = &quot;private&quot;
  }
  </code></pre>
  <p>The bucket gets created successfully</p>
  <p><strong>aws_s3_bucket.lambda_fn_upload: Creation complete after 3s [id=lambda-fns-relieved-copper]</strong></p>
  <p>and key gets created as well using the bucket object</p>
  <p><strong>aws_s3_bucket_object.order_status_file_upload: Creation complete after 4s [id=lambda-fns/orderStatus/function.zip]</strong></p>
  <p>And when I try to use the s3_key in my lambda, it fails</p>
  <pre><code>resource &quot;aws_lambda_function&quot; &quot;order_status&quot; {
    # For files larger than 10 MB, consider uploading using Amazon S3.
    s3_bucket         = aws_s3_bucket.lambda_fn_upload.id
    s3_key            = &quot;lambda-fns/orderStatus/function.zip&quot;
    # filename      = &quot;../orderStatus/function.zip&quot;
    function_name = &quot;orderStatus&quot;
    role          = aws_iam_role.lambda_fn_role.arn
    handler       = &quot;dist/handlers.orderStatus&quot;
  
    source_code_hash = filebase64sha256(&quot;../orderStatus/function.zip&quot;)
  
    runtime = &quot;nodejs12.x&quot;
  
    depends_on = [
      aws_s3_bucket.lambda_fn_upload
    ]
  }
  </code></pre>
  <p>I get the following error</p>
  <blockquote>
  <p>Error: error creating Lambda Function (1): InvalidParameterValueException: Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist.</p>
  </blockquote>
  <p>The issue happens when I run both scripts at the same time, if run the bucket script and then run the lambda script it doesn't fail.</p>