# 5.1.2 Make Serverless Web Application

먼저 AWS Lambda를 이용하여 Public 서비스 백엔드를 구성해보겠습니다. AWS Lambda는 서버를 프로비저닝 또는 관리하지 않고도 실제로 모든 유형의 애플리케이션  또는 백엔드 서비스에 대한 코드를 실행할 수 있는 이벤트 중심의 서버리스 컴퓨팅 서비스입니다.&#x20;

<figure><img src="/files/KxM6Xdeoo2eTrWcMlac3" alt=""><figcaption></figcaption></figure>

AWS Lambda는 서버를 프로비저닝하거나 관리하지 않고도 코드를 실행할 수 있는 서버리스 컴퓨팅 서비스입니다. 다양한 개발 언어를 지원하고 있기 때문에 사실상 모든 유형의 애플리케이션이나 백엔드 서비스에 대한 코드를 별도의 관리 없이 실행할 수 있으며, 사용한 만큼만 비용을 지불합니다. Lambda의 요금은 함수 요청 수와 코드를 실행하는 데 걸리는 기간에 따라 요금을 청구합니다.

이번 실습에서는 AWS Lambda를 이용하여 Web Application을 배포해보도록 하겠습니다.

1. 먼저 AWS Console에서 Lambda를 검색한 후 이동합니다.
2. Lambda의 함수 탭에서 우상단에 있는 함수 생성 버튼을 클릭합니다.

<figure><img src="/files/ZFxhl7zJ04TRe615EBST" alt=""><figcaption></figcaption></figure>

3. Lambda는 새로 작성을 체크하고, 함수 이름, 런타임과 같은 기본정보를 입력한 후 우하단에 있는 함수 생성을 클릭합니다.

<figure><img src="/files/jM1NDqf3jZG6lMrxIy3M" alt=""><figcaption></figcaption></figure>

4. [5.1 Build Web Application with Custom Model Endpoint](/sagemaker-image-workshop/lab5.-build-application-with-your-model/5.1-build-web-application-with-custom-model-endpoint.md) 에서 다운로드 했던 압축파일을 **코드 -> 업로드 -> .zip파일**을 클릭한 후 업로드 합니다.

<figure><img src="/files/JDv4M2eKYmuCwBeWRy28" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/YnXZCTIkkJ9qln6DwGP8" alt=""><figcaption></figcaption></figure>

5. 소스코드가 업로드되면 html/index.html 파일을 열어서 [5.1.1 User Management](/sagemaker-image-workshop/lab5.-build-application-with-your-model/5.1-build-web-application-with-custom-model-endpoint/5.1.1-user-management.md)에서 복사했던 코드를 붙여 넣고, 저장합니다.

```
const AWS_REGION = 'ap-northeast-2'
const IDENTITY_POOL_ID = 'ap-northeast-2:####'
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
      IdentityPoolId: IDENTITY_POOL_ID,
    });
```

6. video.js 파일에 있는 EndpointName 을 배포한 모델의 이름으로 설정합니다.

{% hint style="info" %}
이전 실습을 기본 설정으로 진행했다면,&#x20;

[4.3 Deploy SageMaker Endpoint With Pretrained Model](/sagemaker-image-workshop/lab4.-use-your-own-model-or-algorithm/4.3-deploy-sagemaker-endpoint-with-pretrained-model.md): Yolov8로 시작하는 endpoint의 이름을 입력하세요.

[4.4 Build SageMaker Pipelines with Custom Container](/sagemaker-image-workshop/lab4.-use-your-own-model-or-algorithm/4.4-build-sagemaker-pipelines-with-custom-container.md) : pose-deploy-staging / prod 를 입력하세요.
{% endhint %}

7. 설정이 끝났다면, Deploy를 누릅니다.

<figure><img src="/files/KVCXZ6NcHAwBRrQ7UPkP" alt=""><figcaption></figcaption></figure>

8. Sagemaker endpoint의 추론 결과를 가져오기 위해 역할에 invoke endpoint 정책을 추가합니다. Lambda와 연결된 역할에서 권한 추가 - 인라인 정책 생성 - JSON을 선택 후 아래 JSON 파일을 복사합니다.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sagemaker:InvokeEndpoint",
            "Resource": "*"
        }
    ]
}
```

9. 정책이 역할에 잘 추가되었는지 확인합니다.

<figure><img src="/files/lTHSLCB78wFiIk4tKUi2" alt=""><figcaption></figcaption></figure>

지금까지 퍼블릭 백엔드 사용을 위한 AWS Lambda에 소스코드를 배포하고, Sagemaker와 연동하는 실습을 진행했습니다. 다음 과정에서는 브라우저에서 Lambda에 배포한 백엔드와의 api 통신을 위해 Api Gateway를 배포하는 실습을 진행하겠습니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cheolmin-ki.gitbook.io/sagemaker-image-workshop/lab5.-build-application-with-your-model/5.1-build-web-application-with-custom-model-endpoint/5.1.2-make-serverless-web-application.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
