def lambda_handler()

in save-request/app.py [0:0]


def lambda_handler(event, context):
    responseData = {'Status':'Request successfully saved to Dynamo DB'}
    logger.info(json.dumps(event))
    try:
        if event['RequestType'] == 'Delete':
            update_termination_request_status(event['StackId'].split("/")[-1])
            responseData = {'Status':'Request successfully updated as Terminated in Dynamo DB'}
            sendResponse(event, context,'SUCCESS',responseData)
            return True
        elif event['RequestType'] != 'Create':
            responseData = {'Staus':'No Special handling for Updated Stack, skip the event'}
            sendResponse(event, context,'SUCCESS',responseData)
            return True
        wait_url = event['ResourceProperties']['WaitUrl']
        email_id = event['ResourceProperties']['EmailID']
        approval_url = "{}?requestStatus={}&requestId={}".format(api_gw_url, 'Approve', event['StackId'].split("/")[-1])
        rejection_url = "{}?requestStatus={}&requestId={}".format(api_gw_url, 'Reject', event['StackId'].split("/")[-1])
        event['ResourceProperties']['StackId'] = event['StackId']
        pricing_info = json.dumps(event['ResourceProperties']['EC2Pricing'])
        logger.info(type(pricing_info))
        logger.info("Pricing Info: {}".format(pricing_info))
        business_entity = event['ResourceProperties']['BusinessEntity']
        event['ResourceProperties'].pop('EC2Pricing')
        event['ResourceProperties'].pop('BusinessEntity')
        db_item = {
                'partitionKey': partition_key,
                'rangeKey': event['StackId'].split("/")[-1],
                'requestApprovalUrl': approval_url,
                'requestRejectionUrl': rejection_url,
                'stackWaitUrl':wait_url,
                'requestTime': str(datetime.utcnow()),
                'requestorEmail': email_id,
                'requestStatus': 'SAVED',
                'resourceStatus': 'PENDING',
                'businessEntity': business_entity,
                'businessEntityId': '',
                'pricingInfoAtRequest': json.loads(pricing_info, parse_float=Decimal),
                'productName': event['ResourceProperties']['ProductName'],
                'requestPayload': event['ResourceProperties']
            }
        create_approval_req_item(db_item)
        sendResponse(event, context,'SUCCESS',responseData)
        return True
    except Exception as e:
         logger.info("Error while saving the request in datatbase, termiante the stack: {}".format(e))
         sendResponse(event, context, 'FAILED', {})
         return False