NEW: lambda function
This commit is contained in:
parent
af2032a462
commit
bcacaa9c90
27
py/nextSubnetLambda.py
Normal file
27
py/nextSubnetLambda.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""
|
||||||
|
To use this function in lambda, one needs to upload netaddr and this code as a package. here is how
|
||||||
|
pip3 install netaddr -t ./
|
||||||
|
zip -r ../acrolinxNextSubnet.zip .
|
||||||
|
"""
|
||||||
|
from netaddr import *
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
def lambda_handler(event, context):
|
||||||
|
session = boto3.Session(region_name='us-west-2')
|
||||||
|
ec2 = session.resource('ec2')
|
||||||
|
vpc = ec2.Vpc('vpc-7155ca14')
|
||||||
|
subnets = []
|
||||||
|
for subnet in vpc.subnets.all():
|
||||||
|
subnets.append(IPNetwork(subnet.cidr_block))
|
||||||
|
|
||||||
|
lastSubnet = sorted(subnets).pop()
|
||||||
|
|
||||||
|
# TODO implement
|
||||||
|
return {
|
||||||
|
'statusCode': 200,
|
||||||
|
'body': json.dumps(str(lastSubnet.next()))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user