# Avoiding common errors during SageMaker deployment


Disclaimer: Consistent with the honor code, no solutions are provided here, only hints to help troubleshoot two common errors

While working on the Deep Learning capstone “Deploying a Sentiment Analysis Model” project, most of my time was spent troubleshooting two common errors. They were *ResourceLimitExceeded *error and a CORS error of *CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.*

## Resource Limit Error

The error I got was *“ResourceLimitExceeded: An error occurred (ResourceLimitExceeded) when calling the CreateTrainingJob operation: The account-level service limit ‘ml.p2.xlarge for training job usage”*

**Fix**

You need to apply for a separate instance for training and deployment. [This](https://udacity.zendesk.com/hc/en-us/articles/360037696812-How-do-I-request-a-limit-increase-for-my-p2-xlarge-instance-) Udacity resource suggests it does not matter whether you choose SageMaker Training or SageMaker Deployment

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1630771895420/_SGmK9GPi.png)

It DOES matter. If you are doing the Udacity exercise for training (as below) you need to request the SageMaker Training Resource Type and not SageMaker Hosting.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1630771896873/rQTR7vaj9.png)

The training and hosting(deployment) instances have to be requested separately even if it’s the same instance, for example, ml.m4.xlarge, you need to request twice and specify training and hosting.

My own error occurred because I had requested SageMaker Hosting and was trying to use it for training. After contacting AWS and consulting [online resources](https://github.com/awslabs/amazon-sagemaker-examples/issues/307) I was able to resolve it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1630771898804/bRvXM_RVS.png)

## CORS error

The error I got was *AWS sagemaker error has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. *However the error is NOT because we need to change a CORS setting

**Potential Fixes and hints:**

1. For *Step 7 (again): Use the model for the web app *complete *all* the steps at one go, as many of the steps that follow interdependent

1. The endpoint needs to be deployed and running, if it is not running or not deployed, it will not work

1. The method used to execute the Lambda function is the endpoint created using API Gateway. This endpoint will be a URL that listens for data to be sent to it. So if the URL provided is not correct, an error is generated. Make sure you have the right endpoint in the lambda code. This was what was causing my error.


## Additional Resources

* [Is this movie a thriller](http://francescopochetti.com/is-this-movie-a-thrillerinvoking-a-sagemaker-deep-learning-model-in-an-end-to-end-serverless-web-application/)? Exposing a SageMaker Deep Learning Model in an end to end serverless web application

* [Resource limit when deploying](https://github.com/awslabs/amazon-sagemaker-examples/issues/307)

