Aggiungere un file di specifiche dell'applicazione a una revisione per CodeDeploy - AWS CodeDeploy

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Aggiungere un file di specifiche dell'applicazione a una revisione per CodeDeploy

Questo argomento mostra come aggiungere un AppSpec file alla distribuzione. Include anche modelli per creare un AppSpec file per una distribuzione AWS Lambda ed EC2/on-premise.

Aggiungi un AppSpec file per una distribuzione Amazon ECS

Per una distribuzione su una piattaforma di calcolo Amazon ECS:

  • Il AppSpec file specifica la definizione del task di Amazon ECS utilizzata per la distribuzione, una mappatura del nome del contenitore e delle porte utilizzata per instradare il traffico e le funzioni Lambda opzionali eseguite dopo gli eventi del ciclo di vita della distribuzione.

  • Una revisione è uguale a un file. AppSpec

  • Un AppSpec file può essere scritto usando JSON o YAML.

  • Un AppSpec file può essere salvato come file di testo o inserito direttamente in una console quando si crea una distribuzione. Per ulteriori informazioni, consulta Crea un'implementazione di Amazon ECS Compute Platform (console).

Per creare un AppSpec file

  1. Copia il modello JSON o YAML in un editor di testo o nell' AppSpec editor della console.

  2. Modifica il modello in base alle esigenze.

  3. Usa un validatore JSON o YAML per convalidare il file. AppSpec Se utilizzi l' AppSpeceditor, il file viene convalidato quando scegli Crea distribuzione.

  4. Se si utilizza un editor di testo, salvare il file. Se utilizzi il AWS CLI per creare la tua distribuzione, fai riferimento al AppSpec file se si trova sul tuo disco rigido o in un bucket Amazon S3. Se usi la console, devi inviare il AppSpec file ad Amazon S3.

Modello di AppSpec file YAML per una distribuzione Amazon ECS con istruzioni

Di seguito è riportato un modello YAML di un AppSpec file per una distribuzione Amazon ECS con tutte le opzioni disponibili. Per informazioni sugli eventi del ciclo di vita da utilizzare nella sezione hooks, consulta AppSpec sezione 'hooks' per una distribuzione 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 per un modello di distribuzione Amazon ECS

Di seguito è riportato un modello JSON per un AppSpec file per una distribuzione Amazon ECS con tutte le opzioni disponibili. Per le istruzioni relative al modello, consulta i commenti nella versione YAML nella sezione precedente. Per informazioni sugli eventi del ciclo di vita da utilizzare nella sezione hooks, consulta AppSpec sezione 'hooks' per una distribuzione 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": "" } ] }

Aggiungere un AppSpec file per una distribuzione AWS Lambda

Per una distribuzione su una piattaforma di elaborazione AWS Lambda:

  • Il AppSpec file contiene istruzioni sulle funzioni Lambda da distribuire e utilizzare per la convalida della distribuzione.

  • Una revisione è uguale a un file. AppSpec

  • Un AppSpec file può essere scritto usando JSON o YAML.

  • Un AppSpec file può essere salvato come file di testo o inserito direttamente in un AppSpec editor di console durante la creazione di una distribuzione. Per ulteriori informazioni, consulta Creare un'implementazione della AWS Lambda Compute Platform (console).

Per creare un AppSpec file:

  1. Copia il modello JSON o YAML in un editor di testo o nell' AppSpec editor della console.

  2. Modifica il modello in base alle esigenze.

  3. Usa un validatore JSON o YAML per convalidare il file. AppSpec Se utilizzi l' AppSpeceditor, il file viene convalidato quando scegli Crea distribuzione.

  4. Se si utilizza un editor di testo, salvare il file. Se utilizzi il AWS CLI per creare la tua distribuzione, fai riferimento al AppSpec file se si trova sul tuo disco rigido o in un bucket Amazon S3. Se usi la console, devi inviare il AppSpec file ad Amazon S3.

Modello di AppSpec file YAML per una distribuzione con istruzioni AWS Lambda

Per informazioni sugli eventi del ciclo di vita da utilizzare nella sezione Hooks, consulta AppSpec sezione 'hooks' per una distribuzione 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 per un modello di distribuzione AWS Lambda

Nel modello seguente, sostituisci "MyFunction" con il nome della tua AWS Lambda funzione. Nella sezione Hooks opzionale, sostituisci gli eventi del ciclo di vita con o. BeforeAllowTraffic AfterAllowTraffic

Per informazioni sugli eventi del ciclo di vita da utilizzare nella sezione Hooks, consulta AppSpec sezione 'hooks' per una distribuzione AWS Lambda.

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

Aggiungi un AppSpec file per una distribuzione EC2/on-premise

Senza un AppSpec file, CodeDeploy non è possibile mappare i file sorgente nella revisione dell'applicazione alle relative destinazioni o eseguire script per la distribuzione su una piattaforma di elaborazione EC2/on-premise,.

Ogni revisione deve contenere un solo file. AppSpec

Per aggiungere un AppSpec file a una revisione:

  1. Copiare il modello in un editor di testo.

  2. Modifica il modello in base alle esigenze.

  3. Usa un validatore YAML per verificare la validità del tuo file. AppSpec

  4. Salvare il file come appspec.yml nella cartella principale della versione.

  5. Esegui uno dei seguenti comandi per verificare di aver inserito il AppSpec file nella directory principale:

    • Per Linux, macOS o Unix:

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

      Non ci sarà alcun output se il AppSpec file non viene trovato lì.

    • Per Windows:

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

      Se il file non è memorizzato lì, verrà visualizzato un errore AppSpec File Not Found.

  6. Invia la revisione ad Amazon GitHub S3 o.

    Per istruzioni, consulta Invia una revisione CodeDeploy ad Amazon S3 EC2 (/solo distribuzioni locali).

AppSpec modello di file per una distribuzione EC2/on-premise con istruzioni

Nota

Le distribuzioni su istanze di Windows Server non supportano l'elemento. runas Se si esegue la distribuzione su istanze di Windows Server, non includerlo nel file. 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: