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

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

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

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 (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.

Looks like found some kind of solution/work around on
https://github.com/ansible/ansible-modules-core/issues/143
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.

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