CodeDeploy에 대한 개정에 애플리케이션 사양 파일 추가 - AWS CodeDeploy

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

CodeDeploy에 대한 개정에 애플리케이션 사양 파일 추가

이 주제에서는 AppSpec 파일을 배포에 추가하는 방법을 살펴봅니다. 여기에는 AWS Lambda 및 EC2/온프레미스 배포용으로 AppSpec 파일을 만드는 템플릿도 포함됩니다.

Amazon ECS 배포용 AppSpec 파일 추가

Amazon ECS 컴퓨팅 플랫폼에 배포하는 경우:

  • AppSpec 파일은 배포에 사용되는 Amazon ECS 작업 정의, 트래픽을 라우팅하는 데 사용되는 포트 매핑과 컨테이너 이름, 배포 수명 주기 이벤트 후 실행되는 Lambda 함수 옵션을 지정합니다.

  • 개정은 AppSpec 파일과 동일합니다.

  • APSpec 파일은 JSON 또는 YAML을 사용하여 작성할 수 있습니다.

  • AppSpec 파일은 텍스트 파일로 저장하거나 배포를 만들 때 콘솔에 직접 입력할 수 있습니다. 자세한 내용은 Amazon ECS 컴퓨팅 플랫폼에 대한 배포 생성(콘솔) 단원을 참조하세요.

AppSpec 파일을 만들려면

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

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

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

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

지침이 포함된 Amazon ECS 배포용 YAML AppSpec 파일 템플릿

다음은 사용 가능한 모든 옵션이 포함된 Amazon ECS 배포용 AppSpec 파일의 YAML 템플릿입니다. hooks 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 AppSpec Amazon 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 파일 템플릿

다음은 사용 가능한 모든 옵션이 포함된 Amazon ECS 배포용 AppSpec 파일의 JSON 템플릿입니다. 템플릿 지침은 이전 섹션의 YAML 버전에 있는 설명을 참조하세요. hooks 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 AppSpec Amazon 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 파일 추가

AWS Lambda 컴퓨팅 플랫폼에 배포하는 경우:

  • AppSpec 파일에는 배포되고 배포 유효성 검사에 사용할 Lambda 함수에 대한 지침이 포함되어 있습니다.

  • 개정은 AppSpec 파일과 동일합니다.

  • APSpec 파일은 JSON 또는 YAML을 사용하여 작성할 수 있습니다.

  • AppSpec 파일을 텍스트 파일로 저장할 수도 있고 배포 생성 시 콘솔 AppSpec 편집기에 직접 입력할 수도 있습니다. 자세한 내용은 AWS Lambda 컴퓨팅 플랫폼 배포 생성(콘솔) 단원을 참조하세요.

AppSpec 파일을 만들려면:

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

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

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

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

지침이 포함된 AWS Lambda 배포용 YAML AppSpec 파일 템플릿

후크 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 AppSpec AWSLambda 배포를 위한 '후크' 섹션을(를) 참조하세요.

# 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 파일 템플릿

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

후크 섹션에서 사용할 수명 주기 이벤트에 대한 자세한 내용은 AppSpec AWSLambda 배포를 위한 '후크' 섹션을(를) 참조하세요.

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

EC2 온프레미스 배포용 AppSpec 파일 추가

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

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

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

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

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

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

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

  5. AppSpec 파일을 루트 디렉터리에 저장했는지 확인하려면 다음 명령 중 하나를 실행합니다.

    • Linux, macOS 또는 Unix의 경우:

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

      AppSpec 파일을 찾을 수 없으면 출력이 없습니다.

    • Windows의 경우:

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

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

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

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

지침이 포함된 EC2 온프레미스 배포용 AppSpec 파일 템플릿

참고

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: