View a markdown version of this page

비동기 엔드포인트 간접 호출 - Amazon SageMaker AI

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

비동기 엔드포인트 간접 호출

InvokeEndpointAsync를 사용하여 비동기 엔드포인트에 호스팅된 모델에서 추론을 가져옵니다.

참고

아직 업로드하지 않았다면 추론 데이터(예: 기계 학습 모델, 샘플 데이터)를 Amazon S3에 업로드하세요.

두 가지 방법 중 하나로 요청 페이로드를 제공할 수 있습니다. 이러한 옵션은 상호 배타적이며 요청에 정확히 하나를 제공합니다.

  • 인라인 페이로드 - 최대 128,000바이트의 페이로드의 경우 Body 파라미터를 사용하여 요청에서 직접 데이터를 전달합니다. 이렇게 하면 각 간접 호출 전에 Amazon S3에 페이로드를 업로드하지 않아도 됩니다.

  • Amazon S3 위치 - 더 큰 페이로드의 경우 추론 데이터를 Amazon S3에 업로드하고 InputLocation 파라미터와 함께 URI를 전달합니다.

요청에 다음 필드를 지정하세요.

  • 의 경우 추론 페이로드를 인라인으로 Body제공합니다(최대 128,000바이트). 이 또는 InputLocation를 사용하지만 둘 다 사용하지는 않습니다.

  • 에서 추론 데이터의 Amazon S3 위치를 InputLocation지정합니다. 이 또는 Body를 사용하지만 둘 다 사용하지는 않습니다.

  • EndpointName의 경우, 엔드포인트 이름을 지정하세요.

  • (선택 사항) InvocationTimeoutSeconds의 경우 요청의 최대 제한 시간을 설정할 수 있습니다. 요청마다 이 값을 최대 3,600초(1시간)로 설정할 수 있습니다. 요청에 이 필드를 지정하지 않으면 요청 제한 시간이 기본적으로 15분이 됩니다.

다음 예제에서는 먼저 Amazon S3에 입력을 업로드할 필요가 없는 Body 파라미터와 함께 페이로드를 인라인으로 전송합니다.

# Create a low-level client representing Amazon SageMaker Runtime sagemaker_runtime = boto3.client("sagemaker-runtime", region_name=<aws_region>) # Specify the inference payload inline (up to 128,000 bytes) payload = b'{"inputs": "your inference data here"}' # The name of the endpoint. The name must be unique within an AWS 리전 in your AWS 계정. endpoint_name='<endpoint-name>' # After you deploy a model into production using SageMaker AI hosting # services, your client applications use this API to get inferences # from the model hosted at the specified endpoint. response = sagemaker_runtime.invoke_endpoint_async( EndpointName=endpoint_name, Body=payload, ContentType="application/json", InvocationTimeoutSeconds=3600)

또는 Amazon S3에 페이로드를 저장하고 InputLocation 파라미터를 사용하여 해당 위치를 전달할 수 있습니다. 아직 업로드하지 않은 경우 엔드포인트를 호출하기 전에 추론 데이터를 Amazon S3에 업로드합니다.

# Create a low-level client representing Amazon SageMaker Runtime sagemaker_runtime = boto3.client("sagemaker-runtime", region_name=<aws_region>) # Specify the location of the input. Here, a single SVM sample input_location = "s3://bucket-name/test_point_0.libsvm" # The name of the endpoint. The name must be unique within an AWS 리전 in your AWS 계정. endpoint_name='<endpoint-name>' # After you deploy a model into production using SageMaker AI hosting # services, your client applications use this API to get inferences # from the model hosted at the specified endpoint. response = sagemaker_runtime.invoke_endpoint_async( EndpointName=endpoint_name, InputLocation=input_location, InvocationTimeoutSeconds=3600)

요청 ID와 처리 후 API 직접 호출에 대한 응답을 받을 Amazon S3 버킷의 이름이 포함된 JSON 문자열로 응답을 받습니다.