Tambahkan file spesifikasi aplikasi ke revisi untuk CodeDeploy - AWS CodeDeploy

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Tambahkan file spesifikasi aplikasi ke revisi untuk CodeDeploy

Topik ini menunjukkan cara menambahkan AppSpec file ke penerapan Anda. Ini juga mencakup template untuk membuat AppSpec file untuk penyebaran AWS Lambda dan EC2/On-premise.

Menambahkan AppSpec file untuk penyebaran Amazon ECS

Untuk penerapan ke platform komputasi Amazon ECS:

  • AppSpec File tersebut menentukan definisi tugas Amazon ECS yang digunakan untuk penerapan, nama kontainer, dan pemetaan port yang digunakan untuk merutekan lalu lintas, dan fungsi Lambda opsional yang dijalankan setelah peristiwa siklus hidup penerapan.

  • Revisi sama dengan AppSpec file.

  • AppSpec File dapat ditulis menggunakan JSON atau YAMAL.

  • AppSpec File dapat disimpan sebagai file teks atau dimasukkan langsung ke konsol saat Anda membuat penerapan. Untuk informasi selengkapnya, lihat Membuat penerapan Amazon ECS Compute Platform (konsol).

Untuk membuat AppSpec file

  1. Salin template JSON atau YAMAL ke editor teks atau ke AppSpec editor di konsol.

  2. Ubah templat sesuai kebutuhan.

  3. Gunakan validator JSON atau YAMAL untuk memvalidasi file Anda. AppSpec Jika Anda menggunakan AppSpec editor, file divalidasi saat Anda memilih Buat penerapan.

  4. Jika Anda menggunakan editor teks, simpan file. Jika Anda menggunakan file AWS CLI untuk membuat penerapan, rujuk AppSpec file jika ada di hard drive Anda atau di bucket Amazon S3. Jika Anda menggunakan konsol, Anda harus mendorong AppSpec file Anda ke Amazon S3.

Template AppSpec file YAMAL untuk penerapan Amazon ECS dengan instruksi

Berikut ini adalah template YAMAL AppSpec file untuk penyebaran Amazon ECS dengan semua opsi yang tersedia. Untuk informasi tentang peristiwa siklus hidup yang akan digunakan di hooks bagian ini, lihat. AppSpec Bagian 'kait' untuk penerapan 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

AppSpec File JSON untuk template penyebaran Amazon ECS

Berikut ini adalah template JSON untuk AppSpec file untuk penyebaran Amazon ECS dengan semua opsi yang tersedia. Untuk instruksi template, lihat komentar dalam versi YAMAL di bagian sebelumnya. Untuk informasi tentang peristiwa siklus hidup yang akan digunakan di hooks bagian ini, lihat. AppSpec Bagian 'kait' untuk penerapan 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": "" } ] }

Menambahkan AppSpec file untuk penyebaran AWS Lambda

Untuk penerapan ke platform komputasi AWS Lambda:

  • AppSpec File berisi instruksi tentang fungsi Lambda yang akan digunakan dan digunakan untuk validasi penerapan.

  • Revisi sama dengan AppSpec file.

  • AppSpec File dapat ditulis menggunakan JSON atau YAMAL.

  • AppSpec File dapat disimpan sebagai file teks atau dimasukkan langsung ke AppSpec editor konsol saat membuat penerapan. Untuk informasi selengkapnya, lihat Membuat penerapan AWS Lambda Compute Platform (konsol).

Untuk membuat AppSpec file:

  1. Salin template JSON atau YAMAL ke editor teks atau ke AppSpec editor di konsol.

  2. Ubah templat sesuai kebutuhan.

  3. Gunakan validator JSON atau YAMAL untuk memvalidasi file Anda. AppSpec Jika Anda menggunakan AppSpec editor, file divalidasi saat Anda memilih Buat penerapan.

  4. Jika Anda menggunakan editor teks, simpan file. Jika Anda menggunakan file AWS CLI untuk membuat penerapan, rujuk AppSpec file jika ada di hard drive Anda atau di bucket Amazon S3. Jika Anda menggunakan konsol, Anda harus mendorong AppSpec file Anda ke Amazon S3.

Template AppSpec file YAMAL untuk AWS Lambda penerapan dengan instruksi

Untuk informasi tentang peristiwa siklus hidup yang akan digunakan di bagian kait, lihat. AppSpec Bagian 'kait' untuk penerapan AWS 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.

AppSpec File JSON untuk template AWS Lambda penerapan

Dalam template berikut, ganti MyFunction "" dengan nama AWS Lambda fungsi Anda. Di bagian Hooks opsional, ganti peristiwa siklus hidup dengan atau. BeforeAllowTraffic AfterAllowTraffic

Untuk informasi tentang peristiwa siklus hidup yang akan digunakan di bagian Hooks, lihat. AppSpec Bagian 'kait' untuk penerapan AWS Lambda

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

Menambahkan AppSpec file untuk penerapan EC2/On-premise

Tanpa AppSpec file, CodeDeploy tidak dapat memetakan file sumber dalam revisi aplikasi Anda ke tujuannya atau menjalankan skrip untuk penerapan Anda ke platform komputasi EC2/On-premise,.

Setiap revisi harus berisi hanya satu AppSpec file.

Untuk menambahkan AppSpec file ke revisi:

  1. Salin template ke editor teks.

  2. Ubah templat sesuai kebutuhan.

  3. Gunakan validator YAMAL untuk memeriksa validitas file Anda. AppSpec

  4. Simpan file seperti appspec.yml di direktori root revisi.

  5. Jalankan salah satu perintah berikut untuk memverifikasi bahwa Anda telah menempatkan AppSpec file Anda di direktori root:

    • Untuk Linux, macOS, atau Unix:

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

      Tidak akan ada output jika AppSpec file tidak ditemukan di sana.

    • Untuk Windows:

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

      Kesalahan File Not Found akan ditampilkan jika AppSpec file tidak disimpan di sana.

  6. Dorong revisi ke Amazon GitHub S3 atau.

    Untuk petunjuk, lihat Dorong revisi CodeDeploy ke Amazon S3 EC2 (/Hanya penerapan di Tempat).

AppSpec templat file untuk penerapan EC2/Lokal dengan instruksi

catatan

Penerapan ke instance Windows Server tidak mendukung elemen. runas Jika Anda menyebarkan ke instance Windows Server, jangan sertakan dalam file Anda 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: