def notify_admin()

in process-requests/app.py [0:0]


def notify_admin(request, budget):
    logger.info("Request reeived to notify admin for requestid : {}".format(request['rangeKey']))
    now = datetime.now()
    month = now.month
    year = now.year
    curr_month_name = calendar.month_name[month] + ', '+str(year)
    
    topic_arn = budget['notifySNSTopic'] 
    topic = sns.Topic(topic_arn)
    email_id = request['requestorEmail']
    instance_type = request['requestPayload']['InstanceType']
    approval_url = request['requestApprovalUrl']
    rejection_url = request['requestRejectionUrl']
    budget_limit = budget['budgetLimit']
    accrued_blocked = budget['accruedBlockedSpend']
    requested_amt_31days = request['pricingInfoAtRequest']['31DayPrice']
    forecasted_spend = budget['accruedForecastedSpend'] + budget['accruedApprovedSpend']
    actual_spend = budget['actualSpend']
    response = topic.publish(
        Subject='Request for approval to launch a Linux EC2 Instance',
        Message= '\
        Dear Admin,\n\
        An user ('+email_id+') has requested to launch a Linux EC2 instance ('+instance_type+').\n\n\
        Monthly Budget Limit : '+str(budget_limit)+'\n\
        Forecasted spend for month of '+curr_month_name+': '+str(forecasted_spend)+'\n\
        Actual spend for month of '+curr_month_name+' (MTD): '+str(actual_spend)+'\n\
        Total spend of pending requests in pipeline (exclusive of current request): '+str(accrued_blocked - requested_amt_31days)+'\n\
        Exception requested amount (Monthly Recurring): '+str(requested_amt_31days)+'\n\
        \n\nKindly act by clicking the below URLs.\n\n'+
        'Approval Url (click to approve) '+  approval_url+
        '\n\nRejection Url (click to reject) '+rejection_url+
        '\n\nPlease note that request will be auto rejected in 12 hrs if no action is taken\n\n\
        Thanks,\n\
        Product Approval Team\n')
    logger.info("Status of email notification: {}".format(response))
    return True