mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[aws][docs] Add AnsibleAWSModule features to AWS developer guidelines (#38978)
This commit is contained in:
parent
cd39b8263d
commit
33f358383a
1 changed files with 51 additions and 1 deletions
|
@ -43,6 +43,30 @@ Few other changes are required. One possible issue that you might encounter is t
|
|||
does not inherit methods from AnsibleModule by default, but most useful methods
|
||||
are included. If you do find an issue, please raise a bug report.
|
||||
|
||||
When porting, keep in mind that AnsibleAWSModule also will add the default ec2
|
||||
argument spec by default. In pre-port modules, you should see common arguments
|
||||
specfied with:
|
||||
|
||||
```
|
||||
def main():
|
||||
argument_spec = ec2_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
state=dict(default='present', choices=['present', 'absent', 'enabled', 'disabled']),
|
||||
name=dict(default='default'),
|
||||
# ... and so on ...
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec, ...)
|
||||
|
||||
# can be replaced with
|
||||
def main():
|
||||
argument_spec = dict(
|
||||
state=dict(default='present', choices=['present', 'absent', 'enabled', 'disabled']),
|
||||
name=dict(default='default'),
|
||||
# ... and so on ...
|
||||
)
|
||||
module = AnsibleAWSModule(argument_spec=argument_spec, ...)
|
||||
```
|
||||
|
||||
## Bug fixing
|
||||
|
||||
Bug fixes to code that relies on boto will still be accepted. When possible, the code should be
|
||||
|
@ -350,6 +374,32 @@ def describe_some_resource(client, module):
|
|||
module.fail_json_aws(e, msg="Could not describe resource %s" % name)
|
||||
```
|
||||
|
||||
To make use of AWSRetry easier, it can now be wrapped around a client returned
|
||||
by `AnsibleAWSModule`. any call from a client. To add retries to a client,
|
||||
create a client:
|
||||
|
||||
```
|
||||
module.client('ec2', retry_decorator=AWSRetry.jittered_backoff(retries=10))
|
||||
```
|
||||
|
||||
Any calls from that client can be made to use the decorator passed at call-time
|
||||
using the `aws_retry` argument. By default, no retries are used.
|
||||
|
||||
```
|
||||
ec2 = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff(retries=10))
|
||||
ec2.describe_instances(InstanceIds=['i-123456789'], aws_retry=True)
|
||||
|
||||
# equivalent with normal AWSRetry
|
||||
@AWSRetry.jittered_backoff(retries=10)
|
||||
def describe_instances(client, **kwargs):
|
||||
return ec2.describe_instances(**kwargs)
|
||||
|
||||
describe_instances(module.client('ec2'), InstanceIds=['i-123456789'])
|
||||
```
|
||||
|
||||
The call will be retried the specified number of times, so the calling functions
|
||||
don't need to be wrapped in the backoff decorator.
|
||||
|
||||
### Returning Values
|
||||
|
||||
When you make a call using boto3, you will probably get back some useful information that you
|
||||
|
|
Loading…
Reference in a new issue