# 7. 리소스 정리

실습이 끝나면 CDK로 전체 인프라를 삭제합니다. 삭제하지 않으면 Head Node와 FSx 비용이 계속 발생합니다.

***

### 6.1 실행 중인 작업 확인 및 취소

```bash
# Head Node에서 실행
squeue

# 실행 중인 작업이 있다면 모두 취소
scancel --user=ubuntu
```

***

### 6.2 CDK 스택 삭제 (\~20분)

CloudShell 또는 로컬에서 실행합니다:

```bash
cd ~/aws-physical-ai-recipes/training/hyperpod/cdk

npx cdk destroy -c userId=<본인이름> -c region=us-east-1 --force
```

***

### 6.3 삭제 실패 시 조치

S3 버킷이 비어있지 않으면 스택 삭제가 실패할 수 있습니다:

```bash
# 버킷 비우기
aws s3 rm s3://hyperpod-lifecycle-hyperpod-<userId>-<ACCOUNT_ID>-us-east-1 --recursive
aws s3 rm s3://hyperpod-data-hyperpod-<userId>-<ACCOUNT_ID>-us-east-1 --recursive

# 스택 삭제 재시도
aws cloudformation delete-stack \
  --stack-name HyperPod-<userId> \
  --region us-east-1
```

***

### 6.4 삭제 확인

```bash
aws cloudformation describe-stacks \
  --stack-name HyperPod-<userId> \
  --region us-east-1 2>&1

# "Stack with id HyperPod-<userId> does not exist" 가 출력되면 정상 삭제 완료
```

***

### 6.5 비용 참고

| 컴포넌트                       | 시간당 비용         | 비고        |
| -------------------------- | -------------- | --------- |
| Head Node (ml.m5.xlarge)   | \~$0.20        | 상시 운영     |
| Jump Host (t3.micro)       | \~$0.01        | 상시 운영     |
| Train (ml.g6e.12xlarge)    | \~$7.00        | 학습 시에만    |
| Sim (ml.g5.12xlarge, Spot) | \~$2.00        | 시뮬레이션 시에만 |
| FSx (1.2TB)                | \~$0.55        | 상시        |
| MLflow                     | \~$0.10        | 상시        |
| **실습 중 (head only)**       | **\~$0.86/hr** |           |
| **학습 실행 시**                | **\~$8-10/hr** |           |

{% hint style="danger" %}
실습 후 반드시 `cdk destroy`로 리소스를 정리하세요. Head Node와 FSx는 사용하지 않아도 계속 과금됩니다.
{% endhint %}


---

# 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/hyperpod-distributed-training/7.-cleanup.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.
