Robo-Advisor
Enhance the Robo Advisor with an Amazon Lambda Function
In this section, you will create an Amazon Lambda function that will validate the data provided by the user on the Robo Advisor.
-
Start by creating a new Lambda function from scratch and name it
recommendPortfolio. Select Python 3.7 as runtime. -
In the Lambda function code editor, continue by deleting the AWS generated default lines of code, then paste in the starter code provided in
lambda_function.py. -
Complete the
recommend_portfolio()function by adding these validation rules:- The
ageshould be greater than zero and less than 65. - The
investment_amountshould be equal to or greater than 5000.
- The
-
Once the intent is fulfilled, the bot should respond with an investment recommendation based on the selected risk level as follows:
- none: "100% bonds (AGG), 0% equities (SPY)"
- low: "60% bonds (AGG), 40% equities (SPY)"
- medium: "40% bonds (AGG), 60% equities (SPY)"
- high: "20% bonds (AGG), 80% equities (SPY)"
Hint: Be creative while coding your solution, you can have all the code on the
recommend_portfolio()function, or you can split the functionality across different functions, put your Python coding skills in action!
-
Once you finish coding your Lambda function, test it using the sample test events provided for this Challenge.
-
After successfully testing your code, open the Amazon Lex Console and navigate to the
recommendPortfoliobot configuration, integrate your new Lambda function by selecting it in the “Lambda initialization and validation” and “Fulfillment” sections. -
Build your bot, and test it with valid and invalid data for the slots.
"""
def recommend_portfolio(intent_request): """ Performs dialog management and fulfillment for recommending a portfolio. """