summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob <wimnat@users.noreply.github.com>2016-05-24 00:31:41 +1000
committerBrian Coca <bcoca@ansible.com>2016-05-23 10:31:41 -0400
commitb9ab1f9f5c797dbad2d30218a17de1422e379031 (patch)
tree53d133ec262b1b6be3db7cc29f46dab9ce09bff7
parenta780dbf4e191ba10e33a235559036454cce3aceb (diff)
downloadansible-modules-extras-b9ab1f9f5c797dbad2d30218a17de1422e379031.tar.gz
Add section on how to return boto3 CamelCased results (#2279)
-rw-r--r--cloud/amazon/GUIDELINES.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/cloud/amazon/GUIDELINES.md b/cloud/amazon/GUIDELINES.md
index dbfd3ee1..b8ca836b 100644
--- a/cloud/amazon/GUIDELINES.md
+++ b/cloud/amazon/GUIDELINES.md
@@ -211,6 +211,28 @@ except ClientError, e:
module.fail_json(msg=e.message, **camel_dict_to_snake_dict(e.response))
```
+### Returning Values
+
+When you make a call using boto3, you will probably get back some useful information that you should return in the module.
+
+As well as information related to the call itself, you will also have some response metadata. It is OK to return this to
+the user as well as they may find it useful.
+
+Boto3 returns all values CamelCased. Ansible follows Python standards for variable names and uses snake_case. There is a
+helper function in module_utils/ec2.py called `camel_dict_to_snake_dict` that allows you to easily convert the boto3
+response to snake_case.
+
+You should use this helper function and avoid changing the names of values returned by Boto3. E.g. if boto3 returns a
+value called 'SecretAccessKey' do not change it to 'AccessKey'.
+
+```python
+# Make a call to AWS
+result = connection.aws_call()
+
+# Return the result to the user
+module.exit_json(changed=True, **camel_dict_to_snake_dict(result))
+```
+
### Helper functions
Along with the connection functions in Ansible ec2.py module_utils, there are some other useful functions detailed below.