# Difficulties using aws\_s3 to upload files

**URL:** <https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705>\
**Category:** Ansible Project\
**Created:** [October 9, 2017, 6:09pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705 "2017-10-09T18:09:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Sparks](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Alan\_Sparks](https://forum.ansible.com/u/Alan_Sparks)\
**Post date:** [October 9, 2017, 6:09pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705/1 "2017-10-09T18:09:02Z")

</div>

ansible 2.4.0.0  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/home/sparksa/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/dist-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

Also, botocore-1.7.25, boto-2.48.0, boto3-1.4.4-py2.7

I’m having a lot of trouble trying to use the “aws\_s3” module, getting a 403 error every time I run it. For instance:

- aws\_s3:  
profile: “{{ aws\_profile }}”  
region: “{{ aws\_region }}”  
bucket: “{{ aws\_profile }}-{{ cluster\_name }}-bigiq”  
object: “credentials.txt”  
#src: “{{ tempfile.path }}”  
src: foo.txt  
mode: put  
ignore\_nonexistent\_bucket: True  
register: s3object
- debug: var=s3object

The task fails with:

The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_b8Si5z/ansible\_module\_aws\_s3.py”, line 792, in   
main()  
File “/tmp/ansible\_b8Si5z/ansible\_module\_aws\_s3.py”, line 671, in main  
if module.md5(src) == keysum(module, s3, bucket, obj):  
File “/tmp/ansible\_b8Si5z/ansible\_module\_aws\_s3.py”, line 277, in keysum  
key\_check = s3.head\_object(Bucket=bucket, Key=obj)  
File “/usr/local/lib/python2.7/dist-packages/botocore/client.py”, line 310, in \_api\_call  
return self.\_make\_api\_call(operation\_name, kwargs)  
File “/usr/local/lib/python2.7/dist-packages/botocore/client.py”, line 599, in \_make\_api\_call  
raise error\_class(parsed\_response, operation\_name)  
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden

Without the “ignore\_nonexistent\_bucket” option, it also fails with a 403, but a little differently:

The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_TnLiij/ansible\_module\_aws\_s3.py”, line 289, in bucket\_check  
s3.head\_bucket(Bucket=bucket)  
File “/usr/local/lib/python2.7/dist-packages/botocore/client.py”, line 310, in \_api\_call  
return self.\_make\_api\_call(operation\_name, kwargs)  
File “/usr/local/lib/python2.7/dist-packages/botocore/client.py”, line 599, in \_make\_api\_call  
raise error\_class(parsed\_response, operation\_name)  
ClientError: An error occurred (403) when calling the HeadBucket operation: Forbidden

I’ve tried creating the bucket with Ansible (s3\_bucket), and by hand, same result. I’ve also tried uploading the file using awscli - I can upload the file using the same profile successfully.

Can anyone offer any advice what I may be doing wrong? SInce I can upload or list buckets using awscli, it wouldn’t seem to be a real permissions problem…

---

<div class="post-metadata">

**Author:** ![Alan\_Sparks](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Alan\_Sparks](https://forum.ansible.com/u/Alan_Sparks)\
**Post date:** [October 9, 2017, 6:19pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705/2 "2017-10-09T18:19:14Z")

</div>

Also, I should mention, the profile I am using in this task has Administrator access level.

---

<div class="post-metadata">

**Author:** ![Alan\_Sparks](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Alan\_Sparks](https://forum.ansible.com/u/Alan_Sparks)\
**Post date:** [October 9, 2017, 9:37pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705/3 "2017-10-09T21:37:04Z")

</div>

Some more testing… and I’ve found that if I use the “old” auth options (aws\_access\_key, aws\_secret\_key, security\_profile) it works. It throws the 403 if I remove those and put back the “profile” option that is advertised as supported, and works with the s3\_bucket module.

Is this true? Is the “aws\_s3” module broken, and doesn’t support “profile”?

---

<div class="post-metadata">

**Author:** ![Alan\_Sparks](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Alan\_Sparks](https://forum.ansible.com/u/Alan_Sparks)\
**Post date:** [October 9, 2017, 10:47pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705/4 "2017-10-09T22:47:31Z")

</div>

Pretty sure I found a bug in the aws\_s3 module. Looking at modules/cloud/amazon/aws\_s3.py:

602 # Look at s3\_url and tweak connection settings  
603 # if connecting to RGW, Walrus or fakes3  
604 for key in [‘validate\_certs’, ‘security\_token’, ‘profile\_name’]:  
605 aws\_connect\_kwargs.pop(key, None)

The comment implies tweaking if not S3, but there’s no conditional for that. If I copy the module and comment out this block, profiles work. Seems like a mistake.  
-Alan

---

<div class="post-metadata">

**Author:** ![Alan\_Sparks](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Alan\_Sparks](https://forum.ansible.com/u/Alan_Sparks)\
**Post date:** [October 9, 2017, 10:57pm UTC](https://forum.ansible.com/t/difficulties-using-aws-s3-to-upload-files/25705/5 "2017-10-09T22:57:05Z")

</div>

Someone beat me to finding this:  
[https://github.com/ansible/ansible/pull/30930](https://github.com/ansible/ansible/pull/30930)
