title: Why am I getting different errors when trying to read s3 key that does not exist
body: <p>I have two environments. One, I am running from desktop, and one I am running from an aws lambda. Both of these are python. The code I have on my machine is:</p>
  
  <pre><code>import boto3
  s3 = boto3.resource('s3')
  bucket = 'my-bucket'
  obj = s3.Object(bucket,'test.txt')
  try:
      text = obj.get()['Body'].read().decode()
      print("file exists"))
  except s3.meta.client.exceptions.NoSuchKey:
      print("key does not exist")
  
  </code></pre>
  
  <p>When I run this, everything works perfectly fine, as intended. </p>
  
  <p>When I run this on the lambda, I get </p>
  
  <p>An error occurred (AccessDenied) when calling the GetObject operation: Access Denied</p>
  
  <p>My lambda permissions are correct, so it can't be that, as everything works when the file exists. I am deleting the file each run so it has nothing to do with the order I run my test code. To debug, I did this:</p>
  
  <pre><code>except Exception as e:
      print(e)
  </code></pre>
  
  <p>In both my lambda code and local code, to see what the actual error is. 
  In my local machine, the error is:</p>
  
  <p>An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.</p>
  
  <p>When I run it on my lambda, it is </p>
  
  <p>An error occurred (AccessDenied) when calling the GetObject operation: Access Denied</p>
  
  <p>Why am I getting different error messages, and how do I account for this without a lazy "except all Exceptions" solution? Thank you</p>
  
  <p>This is the CFT for my lambda</p>
  
  <pre><code>                {
                    "Effect": "Allow",
                    "Action": [
                      "s3:PutObject",
                      "s3:GetObject",
                      "s3:ListBucket",
                    ],
                    "Resource": {
                      "Fn::Sub": "arn:aws:s3:::my-bucket/*"
                    }
  
                  }
  </code></pre>