

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

# CodeDeploy에 대한 개정에 애플리케이션 사양 파일 추가
<a name="application-revisions-appspec-file"></a>

이 주제에서는 AppSpec 파일을 배포에 추가하는 방법을 살펴봅니다. 또한 AWS Lambda 및 EC2/온프레미스 배포를 위한 AppSpec 파일을 생성하는 템플릿도 포함되어 있습니다.

**Topics**
+ [Amazon ECS 배포용 AppSpec 파일 추가](#add-appspec-file-ecs)
+ [AWS Lambda 배포를 위한 AppSpec 파일 추가](#add-appspec-file-lambda)
+ [EC2 온프레미스 배포용 AppSpec 파일 추가](#add-appspec-file-server)

## Amazon ECS 배포용 AppSpec 파일 추가
<a name="add-appspec-file-ecs"></a>

Amazon ECS 컴퓨팅 플랫폼에 배포하는 경우:
+ AppSpec 파일은 배포에 사용되는 Amazon ECS 작업 정의, 트래픽을 라우팅하는 데 사용되는 포트 매핑과 컨테이너 이름, 배포 수명 주기 이벤트 후 실행되는 Lambda 함수 옵션을 지정합니다.
+ 개정은 AppSpec 파일과 동일합니다.
+ APSpec 파일은 JSON 또는 YAML을 사용하여 작성할 수 있습니다.
+ AppSpec 파일은 텍스트 파일로 저장하거나 배포를 만들 때 콘솔에 직접 입력할 수 있습니다. 자세한 내용은 [Amazon ECS 컴퓨팅 플랫폼에 대한 배포 생성(콘솔)](deployments-create-console-ecs.md) 단원을 참조하세요.

**AppSpec 파일을 만들려면**

1. JSON 또는 YAML 템플릿을 텍스트 편집기에 복사하거나 콘솔의 AppSpec 편집기에 복사합니다.

1. 필요에 따라 템플릿을 수정합니다.

1. JSON 또는 YAML 유효성 검사기를 사용하여 AppSpec 파일을 검증합니다. AppSpec 편집기를 사용하는 경우 **배포 만들기**를 선택할 때 파일이 검증됩니다.

1. 텍스트 편집기를 사용하는 경우 파일을 저장합니다. 를 사용하여 배포 AWS CLI 를 생성하는 경우 AppSpec 파일이 하드 드라이브 또는 Amazon S3 버킷에 있는 경우 해당 파일을 참조하세요. 콘솔을 사용하는 경우 AppSpec 파일을 Amazon S3로 푸시해야 합니다.

### 지침이 포함된 Amazon ECS 배포용 YAML AppSpec 파일 템플릿
<a name="app-spec-template-yaml-ecs"></a>

다음은 사용 가능한 모든 옵션이 포함된 Amazon ECS 배포용 AppSpec 파일의 YAML 템플릿입니다. `hooks` 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 [Amazon ECS 배포를 위한 AppSpec 'hooks' 섹션](reference-appspec-file-structure-hooks.md#appspec-hooks-ecs)을(를) 참조하세요.

```
# This is an appspec.yml template file for use with an Amazon ECS deployment in CodeDeploy.
# The lines in this template that start with the hashtag are 
#   comments that can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# In the Resources section, you must specify the following: the Amazon ECS service, task definition name, 
# and the name and port of the load balancer to route traffic,
# target version, and (optional) the current version of your AWS Lambda function. 
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "" # Specify the ARN of your task definition (arn:aws:ecs:region:account-id:task-definition/task-definition-family-name:task-definition-revision-number)
        LoadBalancerInfo: 
          ContainerName: "" # Specify the name of your Amazon ECS application's container
          ContainerPort: "" # Specify the port for your container where traffic reroutes 
# Optional properties
        PlatformVersion: "" # Specify the version of your Amazon ECS Service
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets: ["",""] # Specify one or more comma-separated subnets in your Amazon ECS service
            SecurityGroups: ["",""] # Specify one or more comma-separated security groups in your Amazon ECS service
            AssignPublicIp: "" # Specify "ENABLED" or "DISABLED"             
# (Optional) In the Hooks section, specify a validation Lambda function to run during 
# a lifecycle event. 
Hooks:
# Hooks for Amazon ECS deployments are:
    - BeforeInstall: "" # Specify a Lambda function name or ARN
    - AfterInstall: "" # Specify a Lambda function name or ARN
    - AfterAllowTestTraffic: "" # Specify a Lambda function name or ARN
    - BeforeAllowTraffic: "" # Specify a Lambda function name or ARN
    - AfterAllowTraffic: "" # Specify a Lambda function name or ARN
```

### Amazon ECS 배포용 JSON AppSpec 파일 템플릿
<a name="app-spec-template-json-ecs"></a>

다음은 사용 가능한 모든 옵션이 포함된 Amazon ECS 배포용 AppSpec 파일의 JSON 템플릿입니다. 템플릿 지침은 이전 섹션의 YAML 버전에 있는 설명을 참조하세요. `hooks` 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 [Amazon ECS 배포를 위한 AppSpec 'hooks' 섹션](reference-appspec-file-structure-hooks.md#appspec-hooks-ecs)을(를) 참조하세요.

```
{
	"version": 0.0,
	"Resources": [
		{
			"TargetService": {
				"Type": "AWS::ECS::Service",
				"Properties": {
    			"TaskDefinition": "",
    			"LoadBalancerInfo": {
    				"ContainerName": "",
    				"ContainerPort":
    			},
    			"PlatformVersion": "",
    			"NetworkConfiguration": {
    				"AwsvpcConfiguration": {
    					"Subnets": [
    						"",
    						""
    					],
    					"SecurityGroups": [
    						"",
    						""
    					],
    					"AssignPublicIp": ""
    				}
    			}
  			}				
			}
		}
	],
	"Hooks": [
		{
			"BeforeInstall": ""
		},
		{
			"AfterInstall": ""
		},
		{
			"AfterAllowTestTraffic": ""
		},
		{
			"BeforeAllowTraffic": ""
		},
		{
			"AfterAllowTraffic": ""
		}
	]
}
```

## AWS Lambda 배포를 위한 AppSpec 파일 추가
<a name="add-appspec-file-lambda"></a>

 AWS Lambda 컴퓨팅 플랫폼에 배포하는 경우:
+ AppSpec 파일에는 배포되고 배포 유효성 검사에 사용할 Lambda 함수에 대한 지침이 포함되어 있습니다.
+ 개정은 AppSpec 파일과 동일합니다.
+ APSpec 파일은 JSON 또는 YAML을 사용하여 작성할 수 있습니다.
+ AppSpec 파일을 텍스트 파일로 저장할 수도 있고 배포 생성 시 콘솔 AppSpec 편집기에 직접 입력할 수도 있습니다. 자세한 내용은 [AWS Lambda 컴퓨팅 플랫폼 배포 생성(콘솔)](deployments-create-console-lambda.md) 단원을 참조하세요.

AppSpec 파일을 만들려면:

1. JSON 또는 YAML 템플릿을 텍스트 편집기에 복사하거나 콘솔의 AppSpec 편집기에 복사합니다.

1. 필요에 따라 템플릿을 수정합니다.

1. JSON 또는 YAML 유효성 검사기를 사용하여 AppSpec 파일을 검증합니다. AppSpec 편집기를 사용하는 경우 **배포 만들기**를 선택할 때 파일이 검증됩니다.

1. 텍스트 편집기를 사용하는 경우 파일을 저장합니다. 를 사용하여 배포 AWS CLI 를 생성하는 경우 AppSpec 파일이 하드 드라이브 또는 Amazon S3 버킷에 있는 경우 해당 파일을 참조하세요. 콘솔을 사용하는 경우 AppSpec 파일을 Amazon S3로 푸시해야 합니다.



### 지침이 포함된 AWS Lambda 배포용 YAML AppSpec 파일 템플릿
<a name="app-spec-template-yaml-lambda"></a>

후크 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 [AWS Lambda 배포를 위한 AppSpec 'hooks' 섹션](reference-appspec-file-structure-hooks.md#appspec-hooks-lambda)을(를) 참조하세요.

```
# This is an appspec.yml template file for use with an AWS Lambda deployment in CodeDeploy.
# The lines in this template starting with the hashtag symbol are 
#   instructional comments and can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# In the Resources section specify the name, alias, 
# target version, and (optional) the current version of your AWS Lambda function. 
Resources:
  - MyFunction: # Replace "MyFunction" with the name of your Lambda function 
      Type: AWS::Lambda::Function
      Properties:
        Name: "" # Specify the name of your Lambda function
        Alias: "" # Specify the alias for your Lambda function
        CurrentVersion: "" # Specify the current version of your Lambda function
        TargetVersion: "" # Specify the version of your Lambda function to deploy
# (Optional) In the Hooks section, specify a validation Lambda function to run during 
# a lifecycle event. Replace "LifeCycleEvent" with BeforeAllowTraffic
# or AfterAllowTraffic. 
Hooks:
    - LifeCycleEvent: "" # Specify a Lambda validation function between double-quotes.
```

### AWS Lambda 배포 템플릿용 JSON AppSpec 파일
<a name="app-spec-template-json-lambda"></a>

다음 템플릿에서 “MyFunction”을 AWS Lambda 함수 이름으로 바꿉니다. 후크 옵션 섹션에서 수명 주기 이벤트를 BeforeAllowTraffic 또는 AfterAllowTraffic으로 바꿉니다.

후크 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 [AWS Lambda 배포를 위한 AppSpec 'hooks' 섹션](reference-appspec-file-structure-hooks.md#appspec-hooks-lambda)을(를) 참조하세요.

```
{
 	"version": 0.0,
 	"Resources": [{
 		"MyFunction": {
 			"Type": "AWS::Lambda::Function",
 			"Properties": {
 				"Name": "",
 				"Alias": "",
 				"CurrentVersion": "",
 				"TargetVersion": ""
 			}
 		}
 	}],
 	"Hooks": [{
 			"LifeCycleEvent": ""
 		}
 	]
 }
```

## EC2 온프레미스 배포용 AppSpec 파일 추가
<a name="add-appspec-file-server"></a>

AppSpec 파일이 없으면 CodeDeploy는 애플리케이션 개정의 소스 파일을 대상에 매핑하거나 EC2/온프레미스 컴퓨팅 플랫폼에 배포하기 위한 스크립트를 실행할 수 없습니다.

각 개정에는 AppSpec 파일을 하나만 포함해야 합니다.

개정에 AppSpec 파일을 추가하려면:

1. 템플릿을 텍스트 편집기에 복사합니다.

1. 필요에 따라 템플릿을 수정합니다.

1. YAML 유효성 검사기를 사용하여 AppSpec 파일을 검증합니다.

1. 파일을 개정의 루트 디렉터리에 `appspec.yml`로 저장합니다.

1. AppSpec 파일을 루트 디렉터리에 저장했는지 확인하려면 다음 명령 중 하나를 실행합니다.
   + Linux, macOS 또는 Unix의 경우:

     ```
     find /path/to/root/directory -name appspec.yml
     ```

     AppSpec 파일을 찾을 수 없으면 출력이 없습니다.
   + Windows의 경우:

     ```
     dir path\to\root\directory\appspec.yml
     ```

     AppSpec 파일이 저장되지 않은 경우 **파일을 찾을 수 없음** 오류가 표시됩니다.

1. 개정을 Amazon S3 또는 GitHub에 푸시합니다.

   지침은 [Amazon S3에 CodeDeploy의 개정 푸시(EC2 온프레미스 배포 전용)](application-revisions-push.md) 단원을 참조하세요.

### 지침이 포함된 EC2 온프레미스 배포용 AppSpec 파일 템플릿
<a name="app-spec-template-server"></a>

**참고**  
 Windows Server 인스턴스에 배포하는 기능은 `runas` 요소를 지원하지 않습니다. Windows Server 인스턴스를 배포하고 있다면 이 요소를 AppSpec 파일에 포함하지 마세요.

```
# This is an appspec.yml template file for use with an EC2/On-Premises deployment in CodeDeploy.
# The lines in this template starting with the hashtag symbol are 
#   instructional comments and can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# Specify "os: linux" if this revision targets Amazon Linux, 
#   Red Hat Enterprise Linux (RHEL), or Ubuntu Server  
#   instances.
# Specify "os: windows" if this revision targets Windows Server instances.
# (You cannot specify both "os: linux" and "os: windows".)
os: linux 
# os: windows
# During the Install deployment lifecycle event (which occurs between the 
#   BeforeInstall and AfterInstall events), copy the specified files 
#   in "source" starting from the root of the revision's file bundle 
#   to "destination" on the Amazon EC2 instance.
# Specify multiple "source" and "destination" pairs if you want to copy 
#   from multiple sources or to multiple destinations.
# If you are not copying any files to the Amazon EC2 instance, then remove the
#   "files" section altogether. A blank or incomplete "files" section
#   may cause associated deployments to fail.
files:
  - source: 
    destination:
  - source:
    destination:
# For deployments to Amazon Linux, Ubuntu Server, or RHEL instances,
#   you can specify a "permissions" 
#   section here that describes special permissions to apply to the files 
#   in the "files" section as they are being copied over to 
#   the Amazon EC2 instance.
#   For more information, see the documentation.
# If you are deploying to Windows Server instances,
#   then remove the 
#   "permissions" section altogether. A blank or incomplete "permissions"
#   section may cause associated deployments to fail.
permissions:
  - object:
    pattern:
    except:
    owner:
    group:
    mode: 
    acls:
      -
    context:
      user:
      type:
      range:
    type:
      -
# If you are not running any commands on the Amazon EC2 instance, then remove 
#   the "hooks" section altogether. A blank or incomplete "hooks" section
#   may cause associated deployments to fail.
hooks:
# For each deployment lifecycle event, specify multiple "location" entries 
#   if you want to run multiple scripts during that event.
# You can specify "timeout" as the number of seconds to wait until failing the deployment 
#   if the specified scripts do not run within the specified time limit for the 
#   specified event. For example, 900 seconds is 15 minutes. If not specified, 
#   the default is 1800 seconds (30 minutes).
#   Note that the maximum amount of time that all scripts must finish executing 
#   for each individual deployment lifecycle event is 3600 seconds (1 hour). 
#   Otherwise, the deployment will stop and CodeDeploy will consider the deployment
#   to have failed to the Amazon EC2 instance. Make sure that the total number of seconds 
#   that are specified in "timeout" for all scripts in each individual deployment 
#   lifecycle event does not exceed a combined 3600 seconds (1 hour).
# For deployments to Amazon Linux, Ubuntu Server, or RHEL instances,
#   you can specify "runas" in an event to
#   run as the specified user. For more information, see the documentation.
#   If you are deploying to Windows Server instances,
#   remove "runas" altogether.
# If you do not want to run any commands during a particular deployment
#   lifecycle event, remove that event declaration altogether. Blank or 
#   incomplete event declarations may cause associated deployments to fail.
# During the ApplicationStop deployment lifecycle event, run the commands 
#   in the script specified in "location" starting from the root of the 
#   revision's file bundle.
  ApplicationStop:
    - location: 
      timeout:
      runas:
    - location: 
      timeout:
      runas: 
# During the BeforeInstall deployment lifecycle event, run the commands 
#   in the script specified in "location".
  BeforeInstall:
    - location: 
      timeout:
      runas: 
    - location: 
      timeout:
      runas:
# During the AfterInstall deployment lifecycle event, run the commands 
#   in the script specified in "location".
  AfterInstall:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
# During the ApplicationStart deployment lifecycle event, run the commands 
#   in the script specified in "location".
  ApplicationStart:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
# During the ValidateService deployment lifecycle event, run the commands 
#   in the script specified in "location".
  ValidateService:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
```