

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Boto3를 사용하여 컴파일된 모델 배포
<a name="neo-deployment-hosting-services-boto3"></a>

모델이 AWS SDK for Python (Boto3) AWS CLI또는 Amazon SageMaker AI 콘솔을 사용하여 컴파일된 경우 [ 사전 조건](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites) 섹션을 충족해야 합니다. 아래 단계에 따라 [Python용 Amazon Web Services SDK(Boto3)](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)를 사용하여 SageMaker NEO 컴파일 모델 생성하고 배포하세요.

**Topics**
+ [모델 배포](#neo-deployment-hosting-services-boto3-steps)

## 모델 배포
<a name="neo-deployment-hosting-services-boto3-steps"></a>

[사전 조건](https://docs.aws.amazon.com//sagemaker/latest/dg/neo-deployment-hosting-services-prerequisites)을 충족한 후에는, `create_model`, `create_enpoint_config` 및 `create_endpoint` API를 사용하세요.

다음 예시는 이러한 API를 사용하여 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)
```

**참고**  
`AmazonSageMakerFullAccess` 및 `AmazonS3ReadOnlyAccess` 정책은 `AmazonSageMaker-ExecutionRole` IAM 역할에 연결되어야 합니다.

`create_model`, `create_endpoint_config` 및 `create_endpoint` API의 전체 구문은 각각 [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) 및 [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)를 참조하세요.

SageMaker AI를 사용하여 모델을 훈련시키지 않은 경우 다음 환경 변수를 지정합니다.

------
#### [ 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"
}
```

------

 SageMaker AI를 사용하여 모델을 훈련한 경우 `SAGEMAKER_SUBMIT_DIRECTORY` 환경 변수를 훈련 스크립트가 포함된 전체 Amazon S3 버킷 URI로 지정합니다.