title: ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
body: <p>I am trying to call a lambda function which will push some messages into the s3 bucket.But every time i am calling the lambda function i am getting the below  error </p>
  
  <pre><code> ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
  </code></pre>
  
  <p>Below is my lambda code </p>
  
  <pre><code>import json
  import boto3
  
  def lambda_handler(event, context):
  s3 = boto3.client("s3")
  #data = json.loads(event["Records"][0]["body"])
  data = event["Records"][0]["body"]
  
  s3.put_object(Bucket="sqsmybucket",Key="data.json", Body=json.dumps(data))
  #print(event) 
  return {
      'statusCode': 200,
      'body': json.dumps('Hello from Lambda!')     
  }
  </code></pre>
  
  <p>I am using a user account which also has the role to access the S3 <a href="https://i.stack.imgur.com/u4ftQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u4ftQ.png" alt="enter image description here"></a></p>
  
  <p>I have checked the s3 bucket permission and all public access are open for it </p>
  
  <p><a href="https://i.stack.imgur.com/OhqNl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OhqNl.png" alt="enter image description here"></a></p>
  
  <p>But i am repeatedly getting below  error message in cloudwatch log </p>
  
  <pre><code>2020-06-05T23:48:20.920+05:30
  
  [ERROR] ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
  Traceback (most recent call last):
   File "/var/task/lambda_function.py", line 9, in lambda_handler
    s3.put_object(Bucket="sqsmybucket",Key="data.json", Body=json.dumps(data))
   File "/var/runtime/botocore/client.py", line 316, in _api_call
   return self._make_api_call(operation_name, kwargs)
   File "/var/runtime/botocore/client.py", line 626, in _make_api_call
    raise error_class(parsed_response, operation_name)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mm6mf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mm6mf.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/Yv2nn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yv2nn.png" alt="enter image description here"></a></p>
  
  <p>Please help i am really clueless about the situation.Thanks in advance.  </p>