AWS prescriptive-guidance documentation change
Summary
Updated documentation with restructuring of troubleshooting section, updated links to Flask and AWS documentation, and minor text improvements.
Security assessment
The changes are primarily documentation improvements, including updating links to point to stable versions, restructuring the troubleshooting section for clarity, and minor text edits. There is no mention of any security vulnerability or patch. The existing security note about debug mode in production remains, but it is not a new addition.
Diff
diff --git a/prescriptive-guidance/latest/patterns/visualize-ai-ml-model-results-using-flask-and-aws-elastic-beanstalk.md b/prescriptive-guidance/latest/patterns/visualize-ai-ml-model-results-using-flask-and-aws-elastic-beanstalk.md index 74061fb97..f1d1efada 100644 --- a//prescriptive-guidance/latest/patterns/visualize-ai-ml-model-results-using-flask-and-aws-elastic-beanstalk.md +++ b//prescriptive-guidance/latest/patterns/visualize-ai-ml-model-results-using-flask-and-aws-elastic-beanstalk.md @@ -5 +5 @@ -SummaryPrerequisites and limitationsArchitectureToolsEpicsRelated resourcesAdditional information +SummaryPrerequisites and limitationsArchitectureToolsEpicsTroubleshootingRelated resourcesAdditional information @@ -17 +17 @@ You can enhance the accessibility of your services and provide a more interactiv -This pattern uses [Flask](https://flask.palletsprojects.com/en/2.0.x/) and [Plotly](https://plotly.com/) to integrate Amazon Comprehend with a custom web application and visualize sentiments and entities from user-provided data. The pattern also provides the steps to deploy an application by using AWS Elastic Beanstalk. You can adapt the application by using [Amazon Web Services (AWS) AI services](https://aws.amazon.com/machine-learning/ai-services/) or with a custom trained model hosted on an endpoint (for example, an [Amazon SageMaker endpoint](https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-model.html)). +This pattern uses [Flask](https://flask.palletsprojects.com/en/stable/) and [Plotly](https://plotly.com/) to integrate Amazon Comprehend with a custom web application and visualize sentiments and entities from user-provided data. The pattern also provides the steps to deploy an application by using AWS Elastic Beanstalk. You can adapt the application by using [AWS AI services](https://aws.amazon.com/machine-learning/ai-services/) or with a custom trained model hosted on an endpoint (for example, an [Amazon SageMaker endpoint](https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-model.html)). @@ -29 +29 @@ This pattern uses [Flask](https://flask.palletsprojects.com/en/2.0.x/) and [Plot - * An understanding of Flask’s web application framework. For more information about Flask, see the [Quickstart](https://flask.palletsprojects.com/en/1.1.x/quickstart) in the Flask documentation. + * An understanding of Flask’s web application framework. For more information about Flask, see the [Quickstart](https://flask.palletsprojects.com/en/stable/quickstart/) in the Flask documentation. @@ -33 +33 @@ This pattern uses [Flask](https://flask.palletsprojects.com/en/2.0.x/) and [Plot - * Elastic Beanstalk Command Line Interface (EB CLI), installed and configured. For more information about this, see [Install the EB CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html) and [Configure the EB CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html) from the AWS Elastic Beanstalk documentation. + * Elastic Beanstalk Command Line Interface (EB CLI), installed and configured. For more information about this, see [Install the EB CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html) and [Configure the EB CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html) from the Elastic Beanstalk documentation. @@ -46,2 +45,0 @@ This pattern uses [Flask](https://flask.palletsprojects.com/en/2.0.x/) and [Plot - * A troubleshooting list that contains common errors and their solutions is available in the _Additional information_ section. - @@ -84 +82 @@ The `application.py` script contains the web application's core functionality, w - * `/data` is a JSON API that presents the data to be visualized in the dashboard. This route reads the user-provided data and uses the functions in `comprehend_helper.py` to send the user data to Amazon Comprehend for sentiment analysis and named entity recognition (NER). Amazon Comprehend’s response is formatted and returned as a JSON object. + * `/data` is a JSON API that presents the data to be visualized in the dashboard. This route reads the user-provided data and uses the functions in `comprehend_helper.py` to send the user data to Amazon Comprehend for sentiment analysis and named entity recognition (NER). The Amazon Comprehend response is formatted and returned as a JSON object. @@ -110 +108 @@ For more information about design considerations for applications deployed using -Elastic Beanstalk deployments are automatically set up with load balancers and auto scaling groups. For more configuration options, see [Configuring Elastic Beanstalk environments](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html) in the AWS Elastic Beanstalk documentation. +Elastic Beanstalk deployments are automatically set up with load balancers and auto scaling groups. For more configuration options, see [Configuring Elastic Beanstalk environments](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html) in the Elastic Beanstalk documentation. @@ -122 +120 @@ Elastic Beanstalk deployments are automatically set up with load balancers and a - * The [Flask](https://flask.palletsprojects.com/en/2.0.x/) framework performs data processing and API calls using Python and offers interactive web visualization with Plotly. + * The [Flask](https://flask.palletsprojects.com/en/stable/) framework performs data processing and API calls using Python and offers interactive web visualization with Plotly. @@ -127 +125 @@ Elastic Beanstalk deployments are automatically set up with load balancers and a -**Code** +**Code repository** @@ -172 +170 @@ Task| Description| Skills required -Authorize Elastic Beanstalk to access the new model.| Make sure that Elastic Beanstalk has the required access permissions for your new model endpoint. For example, if you use an Amazon SageMaker endpoint, your deployment needs to have permission to invoke the endpoint. For more information about this, see [InvokeEndpoint](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html) in the Amazon SageMaker documentation.| Developer, Security architect +Authorize Elastic Beanstalk to access the new model.| Make sure that Elastic Beanstalk has the required access permissions for your new model endpoint. For example, if you use an Amazon SageMaker AI endpoint, your deployment needs to have permission to invoke the endpoint. For more information about this, see [InvokeEndpoint](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html) in the Amazon SageMaker AI documentation.| Developer, Security architect @@ -175 +173 @@ Send the user data to a new model.| To change the underlying ML model in this ap - * `comprehend_helper.py` – This is the Python script that connects with Amazon Comprehend, processes the response, and returns the final result to the application. In this script, you can either route the data to another AI service on the AWS Cloud or you can send the data to a custom model endpoint. We recommend that you also format the results in this script for logical separation and the reusability of this pattern. + * `comprehend_helper.py` – This is the Python script that connects with Amazon Comprehend, processes the response, and returns the final result to the application. In this script, you can either route the data to another AI service on the AWS Cloud, or you can send the data to a custom model endpoint. We recommend that you also format the results in this script for logical separation and the reusability of this pattern. @@ -191,25 +189 @@ Redeploy the Elastic Beanstalk environment.| To ensure that your application cha -## Related resources - - * [Call an Amazon SageMaker model endpoint using Amazon API Gateway and AWS Lambda](https://aws.amazon.com/blogs/machine-learning/call-an-amazon-sagemaker-model-endpoint-using-amazon-api-gateway-and-aws-lambda/) - - * [Deploying a Flask application to Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html) - - * [EB CLI command reference ](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cmd-commands.html) - - * [Setting up your Python development environment](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-development-environment.html) - - - - -## Additional information - -**Troubleshooting list** - -The following are six common errors and their solutions. - -**_Error 1_ ** - - - Unable to assume role "arn:aws:iam::xxxxxxxxxx:role/aws-elasticbeanstalk-ec2-role". Verify that the role exists and is configured correctly. - -**Solution** : If this error occurs when you run `eb create`, create a sample application on the Elastic Beanstalk console to create the default instance profile. For more information about this, see [Creating an Elastic Beanstalk environment](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.environments.html) in the AWS Elastic Beanstalk documentation. +## Troubleshooting @@ -217,6 +191,4 @@ The following are six common errors and their solutions. -**_Error 2_** - - - Your WSGIPath refers to a file that does not exist. - -**Solution:** This error occurs in deployment logs because Elastic Beanstalk expects the Flask code to be named `application.py`. If you chose a different name, run `eb config` and edit the WSGIPath as shown in the following code sample: +Issue| Solution +---|--- +`Unable to assume role "arn:aws:iam::xxxxxxxxxx:role/aws-elasticbeanstalk-ec2-role". Verify that the role exists and is configured correctly.`| If this error occurs when you run `eb create`, create a sample application on the Elastic Beanstalk console to create the default instance profile. For more information about this, see [Creating an Elastic Beanstalk environment](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.environments.html) in the AWS Elastic Beanstalk documentation. +`Your WSGIPath refers to a file that does not exist.`| This error occurs in deployment logs because Elastic Beanstalk expects the Flask code to be named `application.py`. If you chose a different name, run `eb config` and edit the WSGIPath as shown in the following code sample: @@ -231,10 +203,2 @@ The following are six common errors and their solutions. -Make sure that you replace `application.py` with your file name. - -You can also leverage Gunicorn and a Procfile. For more information about this approach, see [Configuring the WSGI server with a Procfile](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-configuration-procfile.html) in the AWS Elastic Beanstalk documentation. - -**_Error 3_** - - - Target WSGI script '/opt/python/current/app/application.py' does not contain WSGI application 'application'. - -**Solution:** Elastic Beanstalk expects the variable that represents your Flask application to be named `application`. Make sure that the `application.py` file uses `application` as the variable name: +Make sure that you replace `application.py` with your file name.You can also leverage Gunicorn and a Procfile. For more information about this approach, see [Configuring the WSGI server with a Procfile](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-configuration-procfile.html) in the AWS Elastic Beanstalk documentation. +`Target WSGI script '/opt/python/current/app/application.py' does not contain WSGI application 'application'.`| Elastic Beanstalk expects the variable that represents your Flask application to be named `application`. Make sure that the `application.py` file uses `application` as the variable name: @@ -245 +209 @@ You can also leverage Gunicorn and a Procfile. For more information about this a -**_Error 4_** +`The EB CLI cannot find your SSH key file for keyname`| Use the EB CLI to specify which key pair to use or to create a key pair for your deployment’s Amazon EC2 instances. To resolve the error, run `eb init -i` and one of the options will ask: @@ -248 +212 @@ You can also leverage Gunicorn and a Procfile. For more information about this a - The EB CLI cannot find your SSH key file for keyname + Do you want to set up SSH for your instances? @@ -250 +214,3 @@ You can also leverage Gunicorn and a Procfile. For more information about this a -**Solution:** Use the EB CLI to specify which key pair to use or to create a key pair for your deployment’s EC2 instances. To resolve the error, run `eb init -i` and one of the options will ask: +Respond with `Y` to either create a key pair or specify an existing key pair. +I’ve updated my code and redeployed, but my deployment is not reflecting my changes.| If you’re using a Git repository with your deployment, make sure that you add and commit your changes before redeploying. +You are previewing the Flask application from an AWS Cloud9 IDE and run into errors.| For more information about this, see [Previewing running applications in the AWS Cloud9 IDE](https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html) in the AWS Cloud9 documentation. @@ -251,0 +218 @@ You can also leverage Gunicorn and a Procfile. For more information about this a +## Related resources @@ -253 +220 @@ You can also leverage Gunicorn and a Procfile. For more information about this a - Do you want to set up SSH for your instances? + * [Call an Amazon SageMaker AI model endpoint using Amazon API Gateway and AWS Lambda](https://aws.amazon.com/blogs/machine-learning/call-an-amazon-sagemaker-model-endpoint-using-amazon-api-gateway-and-aws-lambda/) @@ -255 +222 @@ You can also leverage Gunicorn and a Procfile. For more information about this a -Respond with `Y` to either create a key pair or specify an existing key pair. + * [Deploying a Flask application to Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html) @@ -257 +224 @@ Respond with `Y` to either create a key pair or specify an existing key pair. -**_Error 5_** + * [EB CLI command reference](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cmd-commands.html) @@ -259 +226 @@ Respond with `Y` to either create a key pair or specify an existing key pair. - _I’ve updated my code and redeployed but my deployment is not reflecting my changes._ + * [Setting up your Python development environment](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-development-environment.html) @@ -261 +227,0 @@ Respond with `Y` to either create a key pair or specify an existing key pair. -**Solution** : If you’re using a Git repository with your deployment, make sure that you add and commit your changes before redeploying. @@ -263 +228,0 @@ Respond with `Y` to either create a key pair or specify an existing key pair. -**_Error 6_** @@ -265 +229,0 @@ Respond with `Y` to either create a key pair or specify an existing key pair. - _You are previewing the Flask application from an AWS Cloud9 IDE and run into errors._ @@ -267 +231 @@ Respond with `Y` to either create a key pair or specify an existing key pair. -**Solution:** For more information about this, see [Previewing running applications in the AWS Cloud9 IDE](https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html) in the AWS Cloud9 documentation. +## Additional information @@ -269 +233 @@ Respond with `Y` to either create a key pair or specify an existing key pair. -**Natural language processing using Amazon Comprehend** + _Natural language processing using Amazon Comprehend_ @@ -277 +241 @@ _BatchDetectEntities_ -Amazon Comprehend inspects the text of a batch of documents for named entities and returns the detected entity, location, [type of entity](https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html), and a score that indicates Amazon Comprehend’s level of confidence. A maximum of 25 documents can be sent in one API call, with each document smaller than 5,000 bytes in size. You can filter the results to show only certain entities based on the use case. For example, you could skip the `‘quantity’` entity type and set a threshold score for the detected entity (for example, 0.75). We recommend that you explore the results for your specific use case before choosing a threshold value. For more information about this, see [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/dg/API_BatchDetectEntities.html) in the Amazon Comprehend documentation. +Amazon Comprehend inspects the text of a batch of documents for named entities and returns the detected entity, location, [type of entity](https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html), and a score that indicates the Amazon Comprehend level of confidence. A maximum of 25 documents can be sent in one API call, with each document smaller than 5,000 bytes in size. You can filter the results to show only certain entities based on the use case. For example, you could skip the `‘quantity’` entity type and set a threshold score for the detected entity (for example, 0.75). We recommend that you explore the results for your specific use case before choosing a threshold value. For more information about this, see [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/dg/API_BatchDetectEntities.html) in the Amazon Comprehend documentation. @@ -283 +247 @@ Amazon Comprehend inspects a batch of incoming documents and returns the prevail -**Flask configuration handling** +_Flask configuration handling_ @@ -285 +249 @@ Amazon Comprehend inspects a batch of incoming documents and returns the prevail -Flask servers use a series of [configuration variables](https://flask.palletsprojects.com/en/1.1.x/config/) to control how the server runs. These variables can contain debug output, session tokens, or other application settings. You can also define custom variables that can be accessed while the application is running. There are multiple approaches for setting configuration variables. +Flask servers use a series of [configuration variables](https://flask.palletsprojects.com/en/stable/config/) to control how the server runs. These variables can contain debug output, session tokens, or other application settings. You can also define custom variables that can be accessed while the application is running. There are multiple approaches for setting configuration variables. @@ -289 +253,3 @@ In this pattern, the configuration is defined in `config.py` and inherited withi - * ###### Note + * `config.py` contains the configuration variables that are set up on the application's startup. In this application, a `DEBUG` variable is defined to tell the application to run the server in [debug mode](https://flask.palletsprojects.com/en/stable/config/#DEBUG). + +###### Note @@ -291 +257 @@ In this pattern, the configuration is defined in `config.py` and inherited withi -`config.py` contains the configuration variables that are set up on the application's startup. In this application, a `DEBUG` variable is defined to tell the application to run the server in [debug mode](https://flask.palletsprojects.com/en/1.1.x/config/#DEBUG). : Debug mode should not be used when running an application in a production environment. `UPLOAD_FOLDER` is a custom variable that is defined to be referenced later in the application and inform it where uploaded user data should be stored. +Debug mode should not be used when running an application in a production environment. `UPLOAD_FOLDER` is a custom variable that is defined to be referenced later in the application and inform it where uploaded user data should be stored.