Last active
August 31, 2016 13:58
-
-
Save dizzythinks/3472019c99124e83d21050ede13c4e14 to your computer and use it in GitHub Desktop.
Boto functional programming example: get private ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import boto3 | |
def get_instances(r): | |
return r['Instances'] | |
def private_ip(i): | |
if i[0].has_key('PrivateIpAddress'): | |
return i[0]['PrivateIpAddress'] | |
def get_private_ips(instanceLookup): | |
return map(private_ip, map(get_instances, instanceLookup['Reservations'])) | |
print(*get_private_ips(boto3.Session().client('ec2').describe_instances()), sep='\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment