

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

# 에서 애플리케이션 생성 AWS SAM
<a name="using-sam-cli-init"></a>

[시작하기](serverless-getting-started.md)를 완료하고 [사용 방법 AWS Serverless Application Model (AWS SAM)](chapter-using-sam.md) 섹션을 읽은 후에는 개발자 환경에서 AWS SAM 프로젝트를 생성할 수 있습니다. AWS SAM 프로젝트는 서버리스 애플리케이션을 작성하는 출발점 역할을 합니다. `sam init` 명령 옵션 목록은 AWS SAM CLI 섹션을 참조하세요[sam init](sam-cli-command-reference-sam-init.md).

 AWS Serverless Application Model 명령줄 인터페이스(AWS SAM CLI) `sam init` 명령은 다음으로 구성된 새 서버리스 애플리케이션을 초기화하는 옵션을 제공합니다.
+ 인프라 코드를 정의하는 AWS SAM 템플릿입니다.
+ 애플리케이션을 구성하는 폴더 구조입니다.
+  AWS Lambda 함수에 대한 구성입니다.

 AWS SAM 프로젝트를 생성하려면이 섹션의 주제를 참조하세요.

**참고**  
`sam init` 에는 지원되는 런타임(TypeScript, Python, Java)의 내구성 있는 함수를 위한 프로젝트 템플릿이 포함되어 있습니다. 이러한 템플릿은 상태 저장 서버리스 애플리케이션을 빌드하기 위한 스타터 코드와 구성을 제공합니다.

**Topics**
+ [새 서버리스 애플리케이션 초기화](#using-sam-cli-init-new)
+ [sam init에 대한 옵션](#using-sam-cli-init-options)
+ [문제 해결](#using-sam-cli-init-troubleshooting)
+ [예제](#using-sam-cli-init-examples)
+ [자세히 알아보기](#using-sam-cli-init-learn)
+ [다음 단계](#w2aac18c11c39)

## 새 서버리스 애플리케이션 초기화
<a name="using-sam-cli-init-new"></a>

**CLI AWS SAM을 사용하여 새 서버리스 애플리케이션을 초기화하려면**

1. `cd`를 시작 디렉터리로.

1. 명령줄 프롬프트에 다음 명령을 실행합니다.

   ```
   $ sam init
   ```

1.  AWS SAMCLI는 새 서버리스 애플리케이션을 만들기 위한 대화형 흐름을 안내합니다.
**참고**  
[자습서:를 사용하여 Hello World 애플리케이션 배포 AWS SAM](serverless-getting-started-hello-world.md)에 자세히 설명된 대로 이 명령은 서버리스 애플리케이션을 초기화하여 프로젝트 디렉터리를 생성합니다. 이 디렉터리에는 여러 파일과 폴더가 포함되어 있습니다. 가장 중요한 파일은 `template.yaml`입니다. 템플릿입니다 AWS SAM . python 버전은 **sam init** 명령이 생성한 `template.yaml` 파일에 나와 있는 python 버전과 일치해야 합니다.

### 시작 템플릿 선택
<a name="using-sam-cli-init-new-template"></a>

*템플릿*은 다음과 같이 구성되어 있습니다.

1. 인프라 코드에 대한 AWS SAM 템플릿입니다.

1. 프로젝트 파일을 구성하는 시작 프로젝트 디렉터리. 예를 들어, 여기에는 다음이 포함될 수 있습니다.

   1. Lambda 함수 코드 및 해당 종속성에 대한 구조.

   1. 로컬 테스트용 테스트 이벤트가 포함된 `events` 폴더.

   1. 유닛 테스트를 지원하는 `tests` 폴더.

   1. 프로젝트 설정을 구성하는 `samconfig.toml` 파일.

   1. `ReadMe` 파일 및 기타 기본 시작 프로젝트 파일.

   다음은 시작 프로젝트 디렉터리의 예입니다.

   ```
   sam-app
   ├── README.md
   ├── __init__.py
   ├── events
   │   └── event.json
   ├── hello_world
   │   ├── __init__.py
   │   ├── app.py
   │   └── requirements.txt
   ├── samconfig.toml
   ├── template.yaml
   └── tests
       ├── __init__.py
       ├── integration
       │   ├── __init__.py
       │   └── test_api_gateway.py
       ├── requirements.txt
       └── unit
           ├── __init__.py
           └── test_handler.py
   ```

사용 가능한 *AWS 빠른 시작 템플릿* 목록에서 선택하거나 *사용자 지정 템플릿 위치*를 제공할 수 있습니다.

**AWS 빠른 시작 템플릿을 선택하려면**

1. 메시지가 표시되면 **AWS 빠른 시작 템플릿**을 선택합니다.

1. 시작할 AWS 퀵 스타트 템플릿을 선택합니다. 다음은 예제입니다.

   ```
   Which template source would you like to use?
       1 - AWS Quick Start Templates
       2 - Custom Template Location
   Choice: 1
   
   Choose an AWS Quick Start application template
       1 - Hello World Example
       2 - Multi-step workflow
       3 - Serverless API
       4 - Scheduled task
       5 - Standalone function
       6 - Data processing
       7 - Hello World Example With Powertools
       8 - Infrastructure event management
       9 - Serverless Connector Hello World Example
       10 - Multi-step workflow with Connectors
       11 - Lambda EFS example
       12 - DynamoDB Example
       13 - Machine Learning
   Template: 4
   ```

**사용자 지정 템플릿 위치를 직접 선택하려면**

1. 메시지가 표시되면 **사용자 지정 템플릿** 위치를 선택합니다.

   ```
   Which template source would you like to use?
       1 - AWS Quick Start Templates
       2 - Custom Template Location
   Choice: 2
   ```

1.  AWS SAMCLI에 템플릿 위치를 제공하라는 메시지가 표시됩니다.

   ```
   Template location (git, mercurial, http(s), zip, path):
   ```

   템플릿 .zip 파일 아카이브에 다음 위치 중 하나를 제공합니다.
   + **GitHub 리포지토리** - GitHub 리포지토리에 있는 .zip 파일의 경로입니다. 파일은 리포지토리의 루트에 있어야 합니다.
   + **Mercurial 리포지토리** - Mercurial 리포지토리에 있는 .zip 파일의 경로입니다. 파일은 리포지토리의 루트에 있어야 합니다.
   + **.zip 경로** -.zip 파일의 HTTPS 또는 로컬 경로입니다.

1.  AWS SAMCLI는 사용자 지정 템플릿을 사용하여 서버리스 애플리케이션을 초기화합니다.

### 런타임 선택
<a name="using-sam-cli-init-new-runtime"></a>

*AWS 빠른 시작 템플릿*을 선택하면 AWS SAMCLI에 Lambda 함수의 런타임을 선택하라는 메시지가 표시됩니다. AWS SAMCLI에 표시되는 옵션 목록은 Lambda에서 기본적으로 지원하는 런타임입니다.
+ [런타임](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-concepts.html#gettingstarted-concepts-runtime)은 실행 환경에서 실행되는 언어별 환경을 제공합니다.
+ 에 배포되면 AWS 클라우드 Lambda 서비스는 [실행](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html) 환경에서 함수를 호출합니다.

사용자 지정 런타임과 함께 다른 프로그래밍 언어를 사용할 수 있습니다. 이렇게 하려면 시작 애플리케이션 구조를 수동으로 만들어야 합니다. 그런 다음 `sam init`를 사용하여 사용자 지정 템플릿 위치를 구성하여 애플리케이션을 빠르게 초기화할 수 있습니다.

선택 항목에 따라 AWS SAMCLI는 Lambda 함수 코드 및 종속성에 대한 시작 디렉터리를 생성합니다.

Lambda가 런타임에 대해 여러 종속성 관리자를 지원하는 경우, 선호하는 종속성 관리자를 선택하라는 메시지가 표시됩니다.

### 패키지 유형 선택
<a name="using-sam-cli-init-new-package"></a>

*AWS 빠른 시작 템플릿*과 *런타임*을 선택하면 AWS SAMCLI에 *패키지 유형*을 선택하라는 메시지가 표시됩니다. 패키지 유형은 Lambda 서비스에서 사용하기 위해 Lambda 함수를 배포하는 방법을 결정합니다. 지원되는 두 가지 패키지 유형은 다음과 같습니다.

1. **컨테이너 이미지**에는 기본 운영 체제, 런타임, Lambda 익스텐션, 애플리케이션 코드 및 해당 종속 항목이 포함됩니다.

1. **.zip 파일 아카이브**에는 애플리케이션 코드와 해당 종속 항목이 포함됩니다.

배포 패키지 유형에 대해 자세히 알아보려면 *AWS Lambda 개발자 안내서*의 [Lambda 배포 패키지](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html)를 참조하세요.

다음은 컨테이너 이미지로 패키징된 Lambda 함수를 사용하는 애플리케이션의 예제 디렉터리 구조입니다. 는 AWS SAM CLI 이미지를 다운로드하고 함수의 디렉터리`Dockerfile`에를 생성하여 이미지를 지정합니다.

```
sam-app
├── README.md
├── __init__.py
├── events
│   └── event.json
├── hello_world
│   ├── Dockerfile
│   ├── __init__.py
│   ├── app.py
│   └── requirements.txt
├── samconfig.toml
├── template.yaml
└── tests
    ├── __init__.py
    └── unit
        ├── __init__.py
        └── test_handler.py
```

다음은 .zip 파일 아카이브로 패키징된 함수를 사용하는 애플리케이션의 예제 디렉터리 구조입니다.

```
sam-app
├── README.md
├── __init__.py
├── events
│   └── event.json
├── hello_world
│   ├── __init__.py
│   ├── app.py
│   └── requirements.txt
├── samconfig.toml
├── template.yaml
└── tests
    ├── __init__.py
    ├── integration
    │   ├── __init__.py
    │   └── test_api_gateway.py
    ├── requirements.txt
    └── unit
        ├── __init__.py
        └── test_handler.py
```

### AWS X-Ray 추적 구성
<a name="using-sam-cli-init-new-tracing"></a>

 AWS X-Ray 추적을 활성화하도록 선택할 수 있습니다. 자세한 내용은 *AWS X-Ray 개발자 안내서*의 [What is AWS X-Ray?](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html)를 참조하세요.

활성화하면가 AWS SAM CLI AWS SAM 템플릿을 구성합니다. 다음은 예제입니다.

```
Globals:
  Function:
    ...
    Tracing: Active
  Api:
    TracingEnabled: True
```

### Amazon CloudWatch Application Insights를 사용한 모니터링 설정
<a name="using-sam-cli-init-new-insights"></a>

Amazon CloudWatch Application Insights를 사용하여 모니터링을 활성화하도록 선택할 수 있습니다. 자세한 내용은 *Amazon CloudWatch 사용 설명서*의 [Amazon CloudWatch Application Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html)를 참조하세요.

활성화하면가 AWS SAM CLI AWS SAM 템플릿을 구성합니다. 다음은 예제입니다.

```
Resources:
  ApplicationResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      ResourceQuery:
        Type: CLOUDFORMATION_STACK_1_0
  ApplicationInsightsMonitoring:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      AutoConfigurationEnabled: 'true'
    DependsOn: ApplicationResourceGroup
```

### 애플리케이션 이름을 지정합니다.
<a name="using-sam-cli-init-new-name"></a>

애플리케이션의 이름을 제공합니다. AWS SAMCLI는 이 이름을 사용하여 애플리케이션의 최상위 폴더를 만듭니다.

## sam init에 대한 옵션
<a name="using-sam-cli-init-options"></a>

다음은 `sam init` 명령과 함께 사용할 수 있는 몇 가지 기본 옵션입니다. 콘텐츠 옵션 목록은 [sam init](sam-cli-command-reference-sam-init.md) 섹션을 참조하세요.

### 사용자 지정 템플릿 위치를 사용하여 애플리케이션 초기화
<a name="using-sam-cli-init-options-location"></a>

`--location` 옵션을 사용하고 지원되는 사용자 지정 템플릿 위치를 제공합니다. 다음은 예제입니다.

```
$ sam init --location https://github.com/aws-samples/sessions-with-aws-sam/raw/master/starter-templates/web-app.zip
```

### 대화형 흐름 없이 애플리케이션 초기화
<a name="using-sam-cli-init-options-no-interactive"></a>

`--no-interactive` 옵션을 사용하고 명령줄에서 구성 선택 사항을 제공하여 대화형 흐름을 건너뜁니다. 다음은 예제입니다.

```
$ sam init --no-interactive --runtime go1.x --name go-demo --dependency-manager mod --app-template hello-world
```

## 문제 해결
<a name="using-sam-cli-init-troubleshooting"></a>

문제를 해결하려면 섹션을 AWS SAM CLI참조하세요[AWS SAMCLI 문제 해결](sam-cli-troubleshooting.md).

## 예제
<a name="using-sam-cli-init-examples"></a>

### Hello World AWS Starter 템플릿을 사용하여 새 서버리스 애플리케이션 초기화
<a name="using-sam-cli-init-examples-helloworld"></a>

이 예제는 *자습서: Hello World 애플리케이션 배포*의 [1단계: Hello World 샘플 애플리케이션 초기화](serverless-getting-started-hello-world.md#serverless-getting-started-hello-world-init) 섹션을 참조하세요.

### 사용자 지정 템플릿 위치를 사용하여 새 서버리스 애플리케이션 초기화
<a name="using-sam-cli-init-examples-custom"></a>

다음은 사용자 지정 템플릿에 GitHub 위치를 제공하는 예제입니다.

```
$ sam init --location gh:aws-samples/cookiecutter-aws-sam-python
$ sam init --location git+sh://git@github.com/aws-samples/cookiecutter-aws-sam-python.git
$ sam init --location hg+ssh://hg@bitbucket.org/repo/template-name
```

다음은 로컬 파일 경로의 예제입니다:

```
$ sam init --location /path/to/template.zip
```

다음은 HTTPS로 도달할 수 있는 경로의 예입니다.

```
$ sam init --location https://github.com/aws-samples/sessions-with-aws-sam/raw/master/starter-templates/web-app.zip
```

## 자세히 알아보기
<a name="using-sam-cli-init-learn"></a>

`sam init` 명령 사용에 대한 자세한 내용은 다음을 참조하세요.
+ **[학습 AWS SAM: sam init](https://www.youtube.com/watch?v=9m3R-leD5Xo) ** –의 Serverless Land "학습 AWS SAM" 시리즈입니다YouTube.
+ **[AWS SAM CLI와 함께 사용할 서버리스 애플리케이션 구조화(SAM S2E7 세션)](https://www.youtube.com/watch?v=k9IRdgze9fQ)** – YouTube의 AWS SAM 시리즈 세션

## 다음 단계
<a name="w2aac18c11c39"></a>

이제 AWS SAM 프로젝트를 생성했으므로 애플리케이션 작성을 시작할 준비가 되었습니다. 이를 위해 완료해야 하는 작업에 대한 자세한 지침은 [를 사용하여 인프라 정의 AWS SAM](serverless-authoring.md) 섹션을 참조하세요.