# Access Denied when calling the S3 PutObject operation

**URL:** <https://forum.serverless.com/t/access-denied-when-calling-the-s3-putobject-operation/7298>\
**Category:** Serverless Framework\
**Created:** [February 7, 2019, 9:22pm UTC](https://forum.serverless.com/t/access-denied-when-calling-the-s3-putobject-operation/7298 "2019-02-07T21:22:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlr0329](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rlr0329](https://forum.serverless.com/u/rlr0329)\
**Post date:** [February 7, 2019, 9:22pm UTC](https://forum.serverless.com/t/access-denied-when-calling-the-s3-putobject-operation/7298/1 "2019-02-07T21:22:31Z")

</div>

I am using serverless framework 1.36.3. In my AWS serverless function, I am getting the following error:

An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

Here is the Python3 code snippet:

```
tmpfilename='/tmp/'+filename
csvfile=open(tmpfilename,'w')
writer = csv.DictWriter(csvfile, fieldnames=fieldnames,quotechar='"')
writer.writeheader()
for row in data:
    csvrow={}
    for f in fieldnames:
        csvrow[f]=getFieldValue(row[f])
    writer.writerow(csvrow)
csvfile.close()

myObj=s3.Object(myBucket, filename)
s3response=myObj.put(Body=open(tmpfilename, 'rb'))

```

I verified that the csvfile is getting created and populated with data

This is what is generated in the IAM inline policy for the lambda role:

```
    {
        "Action": [
            "s3:*"
        ],
        "Resource": [
            "arn:aws:s3:::myBucket"
        ],
        "Effect": "Allow"
    }
```

---

<div class="post-metadata">

**Author:** ![rlr0329](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rlr0329](https://forum.serverless.com/u/rlr0329)\
**Post date:** [February 8, 2019, 12:59am UTC](https://forum.serverless.com/t/access-denied-when-calling-the-s3-putobject-operation/7298/2 "2019-02-08T00:59:17Z")

</div>

Problem solved! I needed to add a second resource definition for the files, e.g:  
“arn:aws:s3:::myBucket”,  
“arn:aws:s3:::_/_”
