# AWS Rate exceeded (Throttling), sleep or pause in loop

**URL:** <https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [August 5, 2015, 8:35am UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949 "2015-08-05T08:35:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dainiax](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dainiax](https://forum.ansible.com/u/Dainiax)\
**Post date:** [August 5, 2015, 8:35am UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949/1 "2015-08-05T08:35:39Z")

</div>

Hello,

Ansible 1.9.2

Im working with Ansible AWS modules. I wanted to create 5 ELB for testing surpose.  
Script:  
…

- name: Create ELBs  
connection: local  
ec2\_elb\_lb:  
aws\_access\_key: “{{ AWS\_ACCESS\_KEY\_ID }}”  
aws\_secret\_key: “{{ AWS\_SECRET\_ACCESS\_KEY }}”  
name: “{{ item.name }}{{ item.elb\_id }}”  
state: present  
connection\_draining\_timeout: 60  
cross\_az\_load\_balancing: true  
region: eu-west-1  
zones:
- eu-west-1a
- eu-west-1b
- eu-west-1c  
listeners:
- protocol: http  
load\_balancer\_port: 80  
instance\_port: 80  
health\_check:  
ping\_protocol: tcp  
ping\_port: 22  
response\_timeout: 5 # seconds  
interval: 30 # seconds  
unhealthy\_threshold: 2  
healthy\_threshold: 5  
with\_items:
- { name: ‘TEST-ELB-’, elb\_id: “01” }
- { name: ‘TEST-ELB-’, elb\_id: “02” }
- { name: ‘TEST-ELB-’, elb\_id: “03” }
- { name: ‘TEST-ELB-’, elb\_id: “04” }
- { name: ‘TEST-ELB-’, elb\_id: “05” }

…

But it failed with errors  
…

Sender `Throttling` Rate exceeded

…  
So is it possible to sleep/pause between iterations of ‘with\_items’ list (as I understand AWS complains about requests coming too fast)?  
Do you have any other solutions for these types of scripts (cause I also get the same errors for attaching instance to multiple ELBs)?

Thank you

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [August 5, 2015, 3:09pm UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949/2 "2015-08-05T15:09:15Z")

</div>

I'd run into a similar issue using the rax\_dns and rax\_dns\_record modules,  
so I created a simple callback plugin to sleep after each task only when  
using the role that ran those modules:  
[https://gist.github.com/cchurch/c2694a1de478ec417ee8](https://gist.github.com/cchurch/c2694a1de478ec417ee8)

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [August 5, 2015, 3:28pm UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949/3 "2015-08-05T15:28:45Z")

</div>

We found that adding serial=1 slowed things down enough to avoid AWS's  
Route 53 rate limits, but that may not help here, if this is all running  
one at a time on a single host anyway...

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Dainiax](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dainiax](https://forum.ansible.com/u/Dainiax)\
**Post date:** [August 6, 2015, 5:02am UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949/4 "2015-08-06T05:02:42Z")

</div>

Looks like found some kind of solution/work around on  
[https://github.com/ansible/ansible-modules-core/issues/143](https://github.com/ansible/ansible-modules-core/issues/143)  
check "**[ndobbs](https://github.com/ndobbs)** commented " examples

It using ‘local\_action’ with ‘until’, ‘retries’ and ‘delay’. So using this example I was able to create 15 ELB in a row without getting/seeing errors.

---

<div class="post-metadata">

**Author:** ![Dainiax](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dainiax](https://forum.ansible.com/u/Dainiax)\
**Post date:** [August 6, 2015, 5:05am UTC](https://forum.ansible.com/t/aws-rate-exceeded-throttling-sleep-or-pause-in-loop/18949/5 "2015-08-06T05:05:55Z")

</div>

An also full example of the script

- name: Create ELBs  
#connection: local  
local\_action:  
module: ec2\_elb\_lb  
aws\_access\_key: “{{ AWS\_ACCESS\_KEY\_ID }}”  
aws\_secret\_key: “{{ AWS\_SECRET\_ACCESS\_KEY }}”  
name: “{{ item.name }}{{ item.elb\_id }}”  
state: present  
connection\_draining\_timeout: 60  
cross\_az\_load\_balancing: true  
region: eu-west-1  
zones:
- eu-west-1a
- eu-west-1b
- eu-west-1c  
listeners:
- protocol: http  
load\_balancer\_port: 80  
instance\_port: 80  
health\_check:  
ping\_protocol: tcp  
ping\_port: 22  
response\_timeout: 5 # seconds  
interval: 30 # seconds  
unhealthy\_threshold: 2  
healthy\_threshold: 5  
with\_items:
- { name: ‘TEST-ELB-’, elb\_id: “01” }
- { name: ‘TEST-ELB-’, elb\_id: “02” }
- { name: ‘TEST-ELB-’, elb\_id: “03” }
- { name: ‘TEST-ELB-’, elb\_id: “04” }
- { name: ‘TEST-ELB-’, elb\_id: “05” }
- { name: ‘TEST-ELB-’, elb\_id: “06” }
- { name: ‘TEST-ELB-’, elb\_id: “07” }
- { name: ‘TEST-ELB-’, elb\_id: “08” }
- { name: ‘TEST-ELB-’, elb\_id: “09” }
- { name: ‘TEST-ELB-’, elb\_id: “10” }
- { name: ‘TEST-ELB-’, elb\_id: “11” }
- { name: ‘TEST-ELB-’, elb\_id: “12” }
- { name: ‘TEST-ELB-’, elb\_id: “13” }
- { name: ‘TEST-ELB-’, elb\_id: “14” }
- { name: ‘TEST-ELB-’, elb\_id: “15” }  
register: ec2\_result

# If instance does not start, try to start it again

until: ec2\_result|success  
retries: 10  
delay: 5
