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

893 views
Skip to first unread message

Dainiax

unread,
Aug 5, 2015, 9:27:57 AM8/5/15
to Ansible Project
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
...
<Error>
    <Type>Sender</Type>
    <Code>Throttling</Code>
    <Message>Rate exceeded</Message>
  </Error>
...
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

Chris Church

unread,
Aug 5, 2015, 11:09:41 AM8/5/15
to ansible...@googlegroups.com
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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8d7409fc-d5d8-4b74-ae9c-004bac8f7dbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Smift

unread,
Aug 5, 2015, 11:29:05 AM8/5/15
to ansible...@googlegroups.com
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...

-Josh (j...@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.

Dainiax

unread,
Aug 6, 2015, 1:02:42 AM8/6/15
to Ansible Project
Looks like found some kind of solution/work around on
check "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.

Dainiax

unread,
Aug 6, 2015, 1:05:55 AM8/6/15
to Ansible Project
An also full example of the script
- name: Create ELBs
      #connection: local
      local_action:
        module: ec2_elb_lb
        - { 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
Reply all
Reply to author
Forward
0 new messages