Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS
Utilizzare UpdateDocument con una CLI
Gli esempi di codice seguenti mostrano come utilizzare UpdateDocument.
- CLI
-
- AWS CLI
-
Come creare una nuova versione di un documento
L’esempio seguente
update-documentcrea una nuova versione di un documento quando viene eseguito su un computer Windows. Il documento specificato da--documentdeve essere in formato JSON. Nota chefile://deve essere referenziato seguito dal percorso del file di contenuto. A causa di$all’inizio del parametro--document-version, in Windows è necessario racchiudere il valore tra virgolette doppie. Su Linux, macOS o al prompt di PowerShell, è necessario racchiudere il valore tra virgolette singole.Versione Windows:
aws ssm update-document \ --name"RunShellScript"\ --content"file://RunShellScript.json"\ --document-version"$LATEST"Versione Linux/Mac:
aws ssm update-document \ --name"RunShellScript"\ --content"file://RunShellScript.json"\ --document-version '$LATEST'Output:
{ "DocumentDescription": { "Status": "Updating", "Hash": "f775e5df4904c6fa46686c4722fae9de1950dace25cd9608ff8d622046b68d9b", "Name": "RunShellScript", "Parameters": [ { "Type": "StringList", "Name": "commands", "Description": "(Required) Specify a shell script or a command to run." } ], "DocumentType": "Command", "PlatformTypes": [ "Linux" ], "DocumentVersion": "2", "HashType": "Sha256", "CreatedDate": 1487899655.152, "Owner": "809632081692", "SchemaVersion": "2.0", "DefaultVersion": "1", "LatestVersion": "2", "Description": "Run an updated script" } }-
Per informazioni dettagliate sull’API, consulta UpdateDocument
nella documentazione di riferimento dei comandi della AWS CLI.
-
- PowerShell
-
- Strumenti per PowerShell V4
-
Esempio 1: questo esempio crea una nuova versione di un documento con il contenuto aggiornato del file json specificato. Il documento deve essere in formato JSON. È possibile ottenere la versione del documento con il cmdlet “Get-SSMDocumentVersionList”.
Update-SSMDocument -Name RunShellScript -DocumentVersion "1" -Content (Get-Content -Raw "c:\temp\RunShellScript.json")Output:
CreatedDate : 3/1/2017 2:59:17 AM DefaultVersion : 1 Description : Run an updated script DocumentType : Command DocumentVersion : 2 Hash : 1d5ce820e999ff051eb4841ed887593daf77120fd76cae0d18a53cc42e4e22c1 HashType : Sha256 LatestVersion : 2 Name : RunShellScript Owner : 809632081692 Parameters : {commands} PlatformTypes : {Linux} SchemaVersion : 2.0 Sha1 : Status : Updating-
Per informazioni dettagliate sull’API, consulta UpdateDocument nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4).
-
- Strumenti per PowerShell V5
-
Esempio 1: questo esempio crea una nuova versione di un documento con il contenuto aggiornato del file json specificato. Il documento deve essere in formato JSON. È possibile ottenere la versione del documento con il cmdlet “Get-SSMDocumentVersionList”.
Update-SSMDocument -Name RunShellScript -DocumentVersion "1" -Content (Get-Content -Raw "c:\temp\RunShellScript.json")Output:
CreatedDate : 3/1/2017 2:59:17 AM DefaultVersion : 1 Description : Run an updated script DocumentType : Command DocumentVersion : 2 Hash : 1d5ce820e999ff051eb4841ed887593daf77120fd76cae0d18a53cc42e4e22c1 HashType : Sha256 LatestVersion : 2 Name : RunShellScript Owner : 809632081692 Parameters : {commands} PlatformTypes : {Linux} SchemaVersion : 2.0 Sha1 : Status : Updating-
Per informazioni dettagliate sull’API, consulta UpdateDocument nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5).
-