# 1. 클라우드 인프라 준비 및 환경 확인

AWS CDK를 사용하여 NVIDIA Isaac Lab을 위한 GPU 기반 개발 환경을 자동으로 프로비저닝합니다. VPC, EC2 GPU 인스턴스 (DCV), AWS Batch, EFS, ECR 등 모든 리소스가 한 번의 명령으로 생성됩니다.

### 사전 요구 사항

* [NVIDIA Omniverse License Agreement](https://docs.omniverse.nvidia.com/isaacsim/latest/common/NVIDIA_Omniverse_License_Agreement.html) 동의
* AWS 계정 — 권장 리전: `us-east-1`
* GPU 인스턴스 서비스 할당량 확인 — AWS 콘솔 → [Service Quotas](https://console.aws.amazon.com/servicequotas/) → EC2 → `Running On-Demand G and VT instances` 값이 필요한 vCPU 수 이상인지 확인 (g6e.4xlarge = 16 vCPU)

***

### 1.1 CloudShell 환경 설정 (\~5분)

1. [AWS 콘솔](https://console.aws.amazon.com)에 로그인합니다.
2. 우측 상단 리전을 **US East (N. Virginia) `us-east-1`** 으로 설정합니다.
3. 상단 `>_` 아이콘을 클릭하여 CloudShell을 실행합니다.
4. 아래 명령어를 실행합니다:

```bash
git clone --depth 1 https://github.com/hi-space/aws-physical-ai-recipes.git ~/aws-physical-ai-recipes
source ~/aws-physical-ai-recipes/isaac-lab-workshop/infra-multiuser-groot/scripts/setup-cloudshell.sh
```

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

이 스크립트는 다음을 자동으로 수행합니다:

* 리포지토리 클론 (이미 존재하면 `git pull`)
* Node.js 18+ 설치 (CloudShell 기본 버전이 낮을 수 있음)
* CDK 프로젝트의 npm 의존성 설치 (`aws-cdk-lib` 등)
* AWS CDK CLI 동작 확인

{% hint style="info" %}
재접속 시에는 `source` 명령만 다시 실행하면 됩니다:

```bash
source ~/aws-physical-ai-recipes/isaac-lab-workshop/infra-multiuser-groot/scripts/setup-cloudshell.sh
```

{% endhint %}

***

### 1.2 인프라 배포 (\~30-60분)

관리자가 안내한 **본인 이름**과 **VPC 번호**를 사용하여 배포합니다.

```bash
nohup npx cdk deploy \
  -c userId=<본인이름> \
  -c vpcCidr=10.<번호>.0.0/16 \
  -c isaacSimVersion=5.1.0 \
  -c region=us-east-1 \
  --require-approval never > deploy.log 2>&1 &
```

예시 (alice, 번호 1):

```bash
nohup npx cdk deploy \
  -c userId=alice \
  -c vpcCidr=10.1.0.0/16 \
  -c isaacSimVersion=5.1.0 \
  -c region=us-east-1 \
  --require-approval never > deploy.log 2>&1 &
```

{% hint style="info" %}
CloudShell은 20분 비활성 시 세션이 종료됩니다. `nohup &`으로 실행하므로 세션이 끊겨도 배포는 계속 진행됩니다. **명령어 끝의 `&`를 반드시 포함**해야 백그라운드로 실행됩니다.
{% endhint %}

<details>

<summary>CDK가 생성하는 인프라 구성</summary>

```mermaid
flowchart TB
    User["사용자 (브라우저)"] -->|"HTTPS :8443 (DCV)\nHTTPS :5555 (code-server)"| EC2

    subgraph VPC["VPC (10.x.0.0/16)"]
        subgraph Public["Public Subnet"]
            EC2["EC2 GPU Instance\n(DCV + code-server + Docker)"]
        end
        subgraph Private["Private Subnet"]
            Batch["AWS Batch\n(분산 학습 노드)"]
        end
        EFS[("EFS\n(공유 스토리지)")]
        EC2 <-->|"모델 저장/로드"| EFS
        Batch <-->|"체크포인트 저장"| EFS
    end

    IGW["Internet Gateway"] --> Public
    Public --> NAT["NAT Gateway"]
    NAT --> Private
    ECR["Amazon ECR\n(Docker 이미지 저장소)"] -.->|"이미지 Pull"| Batch
    User -->|"CDK Deploy"| VPC
```

**AWS 서비스 한 줄 설명:**

| 서비스            | 쉬운 비유                                |
| -------------- | ------------------------------------ |
| VPC            | 나만의 격리된 사설 네트워크 (아파트 한 동)            |
| Public Subnet  | 외부에서 접근 가능한 영역 (로비) — DCV 인스턴스가 위치   |
| Private Subnet | 외부 차단, 내부에서만 접근 (서버실) — Batch 노드가 위치 |
| NAT Gateway    | Private Subnet에서 인터넷으로 나가는 단방향 출구    |
| EFS            | EC2와 Batch가 함께 쓰는 네트워크 공유 디스크        |
| ECR            | Docker 이미지 저장소 (Private Docker Hub)  |
| Security Group | 가상 방화벽 — 허용할 포트와 IP 범위를 규칙으로 설정      |

**EC2 인스턴스**

* GPU 인스턴스 (g6e.4xlarge)에 다음을 자동 설치:
  * Ubuntu Desktop (GNOME)
  * NICE DCV (원격 데스크톱)
  * Docker + NVIDIA Container Toolkit
  * code-server (VSCode)
  * NVIDIA Isaac Lab

**보안 설정**

* **Secrets Manager**: DCV/code-server 비밀번호 자동 생성
* **IAM Roles**: EC2용 (S3, ECR, EFS, SSM 접근), Batch용
* **Lambda**: GPU capacity가 있는 AZ 자동 탐색

</details>

**진행 확인:**

```bash
tail -f deploy.log
# 또는 AWS 콘솔 → CloudFormation → 스택: IsaacLab-Stable-<본인이름>
```

***

### 1.3 배포 완료 및 접속 정보 확인

약 40분 후 프로비저닝이 완료되면, (`Outputs:` 출력 시) 접속 정보를 확인합니다:

```bash
cat deploy.log | grep -E 'DcvUrl|CodeServerUrl|SecretArn'
```

**DCV 비밀번호 확인:**

```bash
aws secretsmanager get-secret-value \
  --secret-id $(cat deploy.log | grep SecretArn | awk -F= '{print $2}' | tr -d ' ') \
  --region us-east-1 \
  --query SecretString --output text | python3 -c "import sys,json; print(json.load(sys.stdin)['password'])"
```

또는 AWS 콘솔 내에서 상단 검색창에서 **CloudFormation**을 검색합니다. CloudFormation 스택을 선택하고 **Outputs** 탭을 선택한 다음 **DCVURL** 키를 복사합니다.

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

* **EC2Host**: 인스턴스 ID
* **DCVURL**: DCV 접속 URL (`https://<Public-IP>:8443`)

<details>

<summary>배포 파라미터 요약</summary>

| 파라미터                    | 설명                                 | 기본값                  | 예시                 |
| ----------------------- | ---------------------------------- | -------------------- | ------------------ |
| `userId`                | 본인 식별자 (영문소문자, 숫자, 하이픈)            | `''`                 | `alice`, `team-1`  |
| `vpcCidr`               | VPC 네트워크 대역 (참가자별 고유)              | `10.0.0.0/16`        | `10.1.0.0/16`      |
| `isaacSimVersion`       | Isaac Sim 버전 오버라이드                 | `''` (프로필 기본값)       | `5.1.0`            |
| `region`                | AWS 리전                             | CDK\_DEFAULT\_REGION | `us-east-1`        |
| `versionProfile`        | 소프트웨어 프로필                          | `stable`             | `stable`, `latest` |
| `inferenceInstanceType` | DCV 인스턴스 타입 직접 지정                  | `''` (자동 선택)         | `g6e.4xlarge`      |
| `preferredAZ`           | AZ 선택 (`auto`: GPU capacity 자동 탐색) | `auto`               | `auto`, `0`\~`5`   |
| `allowedCidr`           | DCV 보안 그룹 인바운드 소스 CIDR             | `0.0.0.0/0`          | `203.0.113.0/24`   |
| `grootRepoUrl`          | GR00T 리포지토리 URL (빈 값이면 미설치)        | GitHub URL           |                    |
| `enableCloudWatch`      | CloudWatch Agent 설치 여부             | `false`              | `true`, `false`    |
| `enableCodeServer`      | code-server (VSCode) 설치 여부         | `true`               | `true`, `false`    |

</details>

***

### 1.4 DCV 접속

1. 브라우저에서 **DcvUrl** 열기 (예: `https://1.2.3.4:8443`)
2. 인증서 경고 → "고급" → "계속 진행"

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

`DCVURL` 주소로 들어가면 위와 같이 DCV 로그인 화면이 나옵니다.

> [Amazon DCV (Desktop Cloud Visualization)](https://docs.aws.amazon.com/ko_kr/dcv/latest/adminguide/what-is-dcv.html)는 AWS가 제공하는 고성능 원격 디스플레이 프로토콜입니다. Amazon EC2와 함께 사용하면 그래픽 집약적 애플리케이션을 Amazon EC2 인스턴스에서 원격으로 실행할 수 있습니다. 복잡한 로봇 시뮬레이션과 물리 엔진을 실시간으로 렌더링 하기 위해 사용합니다.

로그인 정보는 AWS Console의 [AWS Secrets Manager](https://docs.aws.amazon.com/ko_kr/secretsmanager/latest/userguide/intro.html)에서 확인할 수 있습니다.

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

**AWS Secrets Manager** - **InstanceCredentials-\*** - **Retrieve Secret** 선택하면, **username**과 **password**를 확인할 수 있습니다.

해당 정보를 사용하여 DCV 세션으로 로그인 하면 Amazon EC2 DCV 인스턴스에서 실행되는 Amazon DCV 원격 디스플레이가 열립니다.

***

### 1.5 환경 설치 확인

```bash
# GPU 드라이버 확인
nvidia-smi

# Docker 이미지 빌드 확인 (컨테이너는 직접 실행 전까지 없음)
docker images | grep isaaclab

# EFS 마운트 확인
df -h | grep efs

# code-server 상태 확인
systemctl status code-server

# GR00T 설치 확인 (활성화한 경우)
ls /home/ubuntu/environment/groot_docker
```

**정상 결과:**

* `nvidia-smi` → GPU 정보 출력 (L40S 또는 L4)
* `docker images | grep isaaclab` → `isaaclab-batch:latest` 이미지 존재
* `df -h | grep efs` → EFS 마운트 포인트 표시
* `code-server` → `active (running)`

**문제가 있으면 UserData 로그 확인:**

```bash
sudo tail -100 /var/log/cloud-init-output.log
```

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

Deep Learning AMI를 사용해 인스턴스를 생성했기 때문에 CUDA, Nvidia Driver, PyTorch 등 기본적인 학습을 위한 환경 설정이 되어 있습니다.

***

### 1.6 code-server (VSCode) 접속

code-server를 통해 브라우저에서 VSCode 환경으로 코드를 편집하고 터미널을 사용할 수 있습니다.

* 브라우저에서 **CodeServerUrl** 열기 (예: `https://1.2.3.4:5555`)
* Password: DCV와 동일 (같은 Secrets Manager 시크릿 사용)

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


---

# 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://hi-space.gitbook.io/physical-ai-on-aws/physical-ai-on-aws-guide/nvidia-isaac-lab-on-aws/1.-infra-setup.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.
