

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Distribuzione di un modello compilato utilizzando Boto3
<a name="neo-deployment-hosting-services-boto3"></a>

Devi soddisfare la sezione dei [prerequisiti](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites) se il modello è stato compilato utilizzando AWS SDK per Python (Boto3) o la console Amazon SageMaker AI. AWS CLI Segui i passaggi seguenti per creare e distribuire un SageMaker Neo-compiled modello utilizzando [Amazon Web Services SDK for Python (Boto3)](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html). 

**Topics**
+ [Implementazione del modello](#neo-deployment-hosting-services-boto3-steps)

## Implementazione del modello
<a name="neo-deployment-hosting-services-boto3-steps"></a>

Dopo aver soddisfatto i [prerequisiti](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites), utilizza le API`create_model`, `create_enpoint_config` e `create_endpoint`. 

L'esempio seguente mostra come utilizzare queste API per distribuire un modello compilato con Neo: 

```
import boto3
client = boto3.client('sagemaker')

# create sagemaker model
create_model_api_response = client.create_model(
                                    ModelName={{'my-sagemaker-model'}},
                                    PrimaryContainer={
                                        'Image': {{<insert the ECR Image URI>}},
                                        'ModelDataUrl': {{'s3://path/to/model/artifact/model.tar.gz'}},
                                        'Environment': {}
                                    },
                                    ExecutionRoleArn={{'ARN for AmazonSageMaker-ExecutionRole'}}
                            )

print ("create_model API response", create_model_api_response)

# create sagemaker endpoint config
create_endpoint_config_api_response = client.create_endpoint_config(
                                            EndpointConfigName={{'sagemaker-neomxnet-endpoint-configuration'}},
                                            ProductionVariants=[
                                                {
                                                    'VariantName': {{<provide your variant name>}},
                                                    'ModelName': {{'my-sagemaker-model}}',
                                                    'InitialInstanceCount': 1,
                                                    'InstanceType': {{<provide your instance type here>}}
                                                },
                                            ]
                                       )

print ("create_endpoint_config API response", create_endpoint_config_api_response)

# create sagemaker endpoint
create_endpoint_api_response = client.create_endpoint(
                                    EndpointName={{'provide your endpoint name'}},
                                    EndpointConfigName={{<insert your endpoint config name>}},
                                )

print ("create_endpoint API response", create_endpoint_api_response)
```

**Nota**  
Le policy `AmazonSageMakerFullAccess` e `AmazonS3ReadOnlyAccess`devono essere collegate al ruolo IAM di `AmazonSageMaker-ExecutionRole`. 

Per la sintassi completa delle API `create_model`, `create_endpoint_config` e `create_endpoint` API, vedi [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_model](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_model), [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint_config](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint_config) e [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_endpoint), rispettivamente. 

Se non hai addestrato il tuo modello utilizzando l' SageMaker intelligenza artificiale, specifica le seguenti variabili di ambiente: 

------
#### [ MXNet and PyTorch ]

```
"Environment": {
    "SAGEMAKER_PROGRAM": "inference.py",
    "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
    "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
    "SAGEMAKER_REGION": {{"insert your region"}},
    "MMS_DEFAULT_RESPONSE_TIMEOUT": "500"
}
```

------
#### [ TensorFlow ]

```
"Environment": {
    "SAGEMAKER_PROGRAM": "inference.py",
    "SAGEMAKER_SUBMIT_DIRECTORY": {{"/opt/ml/model/code"}},
    "SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
    "SAGEMAKER_REGION": {{"insert your region"}}
}
```

------

 Se hai addestrato il tuo modello utilizzando l' SageMaker intelligenza artificiale, specifica la variabile di ambiente `SAGEMAKER_SUBMIT_DIRECTORY` come URI completo del bucket Amazon S3 che contiene lo script di addestramento. 