Repository: ansible/ansible

Issue:
s3: fakes3 not working anymore in >= 2.4.0.0
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
aws_s3

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
2.4.1.0
```

##### OS / ENVIRONMENT
N/A

##### SUMMARY
The `aws_s3` module does not work anymore when using an endpoint with `fakes3`, complaining about method error.

##### STEPS TO REPRODUCE

```yaml
- name: Upload to S3
  hosts: localhost
  connection: local
  tasks:
    - name: list bucket
      aws_s3:
        aws_access_key: "..."
        aws_secret_key: "..."
        s3_url: fakes3s://sos-ch-dk-2.exo.io:443
        region: ch-dk-2
        bucket: test
        mode: list

```

##### EXPECTED RESULTS
Get the bucket content

##### ACTUAL RESULTS
List bucket is failing.

<!--- Paste verbatim command output between quotes below -->
```
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_VZpvff/ansible_module_aws_s3.py", line 859, in <module>
    main()
  File "/tmp/ansible_VZpvff/ansible_module_aws_s3.py", line 674, in main
    s3 = get_s3_connection(module, aws_connect_kwargs, location, rgw, s3_url)
  File "/tmp/ansible_VZpvff/ansible_module_aws_s3.py", line 572, in get_s3_connection
    return boto3_conn(**params)
TypeError: boto3_conn() takes at least 1 argument (0 given)

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_VZpvff/ansible_module_aws_s3.py\", line 859, in <module>\n    main()\n  File \"/tmp/ansible_VZpvff/ansible_module_aws_s3.py\", line 674, in main\n    s3 = get_s3_connection(module, aws_connect_kwargs, location, rgw, s3_url)\n  File \"/tmp/ansible_VZpvff/ansible_module_aws_s3.py\", line 572, in get_s3_connection\n    return boto3_conn(**params)\nTypeError: boto3_conn() takes at least 1 argument (0 given)\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/aws_s3.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/aws_s3.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @lwade @s-hertel @willthames
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/aws_s3.py b/lib/ansible/modules/cloud/amazon/aws_s3.py
--- a/lib/ansible/modules/cloud/amazon/aws_s3.py
+++ b/lib/ansible/modules/cloud/amazon/aws_s3.py
@@ -555,15 +555,19 @@ def get_s3_connection(module, aws_connect_kwargs, location, rgw, s3_url):
         rgw = urlparse(s3_url)
         params = dict(module=module, conn_type='client', resource='s3', use_ssl=rgw.scheme == 'https', region=location, endpoint=s3_url, **aws_connect_kwargs)
     elif is_fakes3(s3_url):
-        for kw in ['is_secure', 'host', 'port'] and list(aws_connect_kwargs.keys()):
-            del aws_connect_kwargs[kw]
         fakes3 = urlparse(s3_url)
+        port = fakes3.port
         if fakes3.scheme == 'fakes3s':
             protocol = "https"
+            if port is None:
+                port = 443
         else:
             protocol = "http"
-        params = dict(service_name='s3', endpoint_url="%s://%s:%s" % (protocol, fakes3.hostname, to_text(fakes3.port)),
-                      use_ssl=fakes3.scheme == 'fakes3s', region_name=None, **aws_connect_kwargs)
+            if port is None:
+                port = 80
+        params = dict(module=module, conn_type='client', resource='s3', region=location,
+                      endpoint="%s://%s:%s" % (protocol, fakes3.hostname, to_text(port)),
+                      use_ssl=fakes3.scheme == 'fakes3s', **aws_connect_kwargs)
     elif is_walrus(s3_url):
         walrus = urlparse(s3_url).hostname
         params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint=walrus, **aws_connect_kwargs)


Test patch: