UPD: added code for cloudformation call back

This commit is contained in:
xpk 2020-06-29 19:45:51 +08:00
parent bcacaa9c90
commit 04a1641132
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86

View File

@ -2,10 +2,12 @@
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 .
The cloudformation call back is to be implemented.
"""
from netaddr import *
import boto3
#import cfnresponse
import json
def lambda_handler(event, context):
@ -17,11 +19,14 @@ def lambda_handler(event, context):
subnets.append(IPNetwork(subnet.cidr_block))
lastSubnet = sorted(subnets).pop()
nextSubnet = str(lastSubnet.next())
# TODO implement
return {
'statusCode': 200,
'body': json.dumps(str(lastSubnet.next()))
'statusCode': 200,
'body': json.dumps(str(lastSubnet.next()))
}
# response_data = {}
# response_data = {"cidr": nextSubnet}
# my_data = nextSubnet
# cfnresponse.send(event,context,cfnresponse.SUCCESS, response_data, my_data)