

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à.

# Creare un documento componente YAML per componenti personalizzati in Image Builder
<a name="create-component-yaml"></a>

Per creare un componente, è necessario fornire un documento relativo al componente dell'applicazione YAML o JSON. Il documento contiene il codice che viene eseguito durante le fasi e i passaggi definiti per personalizzare l'immagine.

Alcuni esempi in questa sezione creano un componente di compilazione che richiama il modulo di `UpdateOS` azione nell'applicazione di gestione dei AWSTOE componenti. Il modulo aggiorna il sistema operativo. Per ulteriori informazioni sul modulo di `UpdateOS` azione, vedere[Aggiorna il sistema operativo](toe-action-modules.md#action-modules-updateos).

L'esempio del sistema operativo macOS utilizza il modulo di `ExecuteBash` azione per installare e verificare l'`wget`utilità. Il modulo di `UpdateOS` azione non supporta macOS. Per ulteriori informazioni sul modulo di `ExecuteBash` azione, consulta[ExecuteBash](toe-action-modules.md#action-modules-executebash). Per ulteriori informazioni sulle fasi, i passaggi e la sintassi dei documenti dei componenti AWSTOE dell'applicazione, consulta [Use documents in AWSTOE](https://docs.aws.amazon.com/imagebuilder/latest/userguide/toe-use-documents.html).

**Nota**  
Image Builder determina il tipo di componente dalle fasi definite nel documento del componente come segue:  
**Build**: questo è il tipo di componente predefinito. Tutto ciò che non è classificato come componente di test è un componente di compilazione. Questo tipo di componente viene eseguito durante la *fase di creazione* dell'immagine. Se questo componente di compilazione ha una `test` fase definita, tale fase viene eseguita durante la *fase di test*.
**Test**: per qualificarsi come componente di test, il documento del componente deve includere solo una fase, denominata`test`. Per i test relativi alle configurazioni dei componenti di compilazione, ti consigliamo di non utilizzare un componente di test autonomo. Piuttosto, usa la `test` fase nel componente di compilazione associato.
Per ulteriori informazioni su come Image Builder utilizza fasi e fasi per gestire il flusso di lavoro dei componenti nel processo di creazione, vedere. [Usa i componenti per personalizzare l'immagine di Image Builder](manage-components.md)

Per creare un documento relativo al componente dell'applicazione YAML per un'applicazione di esempio, seguite i passaggi nella scheda corrispondente al sistema operativo dell'immagine. 

------
#### [ Linux ]

**Crea un file componente YAML**  
Usa uno strumento di modifica dei file per creare il documento componente. Gli esempi di documentazione utilizzano un file denominato`update-linux-os.yaml`, con il seguente contenuto:

```
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
name: update-linux-os
description: Updates Linux with the latest security updates.
schemaVersion: 1
phases:
  - name: build
    steps:
    - name: UpdateOS
      action: UpdateOS
# Document End
```

**Suggerimento**  
Usa uno strumento come questo [validatore YAML](https://jsonformatter.org/yaml-validator) online o un'estensione YAML lint nel tuo ambiente di codice per verificare che il tuo YAML sia ben formato.

------
#### [ Windows ]

**Crea un file componente YAML**  
Usa uno strumento di modifica dei file per creare il documento componente. Gli esempi di documentazione utilizzano un file denominato`update-windows-os.yaml`, con il seguente contenuto:

```
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
name: update-windows-os
description: Updates Windows with the latest security updates.
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: UpdateOS
        action: UpdateOS
# Document End
```

**Suggerimento**  
Usa uno strumento come questo [validatore YAML](https://jsonformatter.org/yaml-validator) online o un'estensione YAML lint nel tuo ambiente di codice per verificare che il tuo YAML sia ben formato.

------
#### [ macOS ]

**Crea un file componente YAML**  
Usa uno strumento di modifica dei file per creare il documento componente. Gli esempi di documentazione utilizzano un file denominato`wget-macos.yaml`, con il seguente contenuto:

```
name: WgetInstallDocument
description: This is wget installation document.
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: WgetBuildStep
        action: ExecuteBash
        inputs:
          commands:
            - |
              PATH=/usr/local/bin:$PATH
              sudo -u ec2-user brew install wget


  - name: validate
    steps:
      - name: WgetValidateStep
        action: ExecuteBash
        inputs:
          commands:
            - |
              function error_exit {
                echo $1
                echo "{\"failureMessage\":\"$2\"}"
                exit 1
              }

              type wget
              if [ $? -ne 0 ]; then
                error_exit "$stderr" "Wget installation failed!"
              fi

  - name: test
    steps:
      - name: WgetTestStep
        action: ExecuteBash
        inputs:
          commands:
            - wget -h
```

**Suggerimento**  
Usa uno strumento come questo [validatore YAML](https://jsonformatter.org/yaml-validator) online o un'estensione YAML lint nel tuo ambiente di codice per verificare che il tuo YAML sia ben formato.

------