Skip to main content

Unbound DNS resolver to answer simple DNS queries using EC2 API calls

Project description

Build Status Version

This module uses the Unbound DNS resolver to answer simple DNS queries using EC2 API calls. For example, the following query would match an EC2 instance with a Name tag of

$ dig -p 5003 @
; <<>> DiG 9.8.1-P1 <<>> -p 5003 @
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5696
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;       IN      A


;; Query time: 81 msec
;; WHEN: Sat Sep 28 23:27:16 2013
;; MSG SIZE  rcvd: 77


On Debian family, install the unbound, python-unbound system packages.

On Redhat family, install the unbound, unbound-python system packages.

Then, install unbound-ec2:

$ pip install unbound-ec2


The following settings must be added to your Unbound configuration:

    chroot: ""
    module-config: "validator python iterator"

    python-script: "/etc/unbound/unbound_ec2_script"

EC2 module can be configured by specifying values in /etc/unbound/unbound_ec2.conf or setting environment variables in /etc/default/unbound.

See unbound_ec2.conf.example and default_unbound.example for more information.

You can also define AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY entries in the environment directory. When unbound-ec2 is run on an EC2 instance, though, it will automatically use an IAM instance profile if one is available.

Configuration - zone forwarding

By default unbound will control the whole zone configured for the plugin, however in some cases you might want to delegate subdomains to other authoritative name servers. Unbound allows this by using the forward-zone directive:

      name: ""
      forward-addr: ""

Additionally, the unbound-ec2 plugin has to be configured with a comma separated list of all subdomains to be forwarded in the [main] section of the unbound_ec2.conf configuration file:

forwarded_zones =


unbound-ec2 queries the EC2 API to answer requests about names inside the specified zone. All other requests are handled normally by Unbound’s caching resolver if caching type server was chosen.

For requests for names within the specified zone, unbound_ec2 calls DescribeInstances and filters the results using defined lookup filters (default is instances in the running state).

When more than one instance matches the DescribeInstances query, unbound-ec2 will return multiple A records in a round-robin. In case of caching type server, query results will be cached by Unbound, and a TTL (default: 300 seconds) is defined to encourage well-behaved clients to cache the information themselves.

IPv6 are not yet supported.

Unit tests

Run with

$ python test

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for unbound-ec2, version 1.3.0
Filename, size File type Python version Upload date Hashes
Filename, size unbound_ec2-1.3.0-py2.7.egg (20.5 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size unbound-ec2-1.3.0.tar.gz (10.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page