2024-09-11 11:06:11 -07:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[ssm.JavaScript.Basics.hello]
import { paginateListDocuments , SSMClient } from "@aws-sdk/client-ssm" ;
// Call ListDocuments and display the result.
export const main = async ( ) => {
const client = new SSMClient ( ) ;
2024-10-16 11:53:18 -04:00
const listDocumentsPaginated = [ ] ;
2024-09-11 11:06:11 -07:00
console . log (
"Hello, AWS Systems Manager! Let's list some of your documents:\n" ,
) ;
try {
// The paginate function is a wrapper around the base command.
const paginator = paginateListDocuments ( { client } , { MaxResults : 5 } ) ;
for await ( const page of paginator ) {
listDocumentsPaginated . push ( ... page . DocumentIdentifiers ) ;
}
} catch ( caught ) {
console . error ( ` There was a problem saying hello: ${ caught . message } ` ) ;
throw caught ;
}
2024-10-16 11:53:18 -04:00
for ( const { Name , DocumentFormat , CreatedDate } of listDocumentsPaginated ) {
2024-09-11 11:06:11 -07:00
console . log ( ` ${ Name } - ${ DocumentFormat } - ${ CreatedDate } ` ) ;
2024-10-16 11:53:18 -04:00
}
2024-09-11 11:06:11 -07:00
} ;
// Call function if run directly.
2024-10-16 11:53:18 -04:00
import { fileURLToPath } from "node:url" ;
2024-09-11 11:06:11 -07:00
if ( process . argv [ 1 ] === fileURLToPath ( import . meta . url ) ) {
main ( ) ;
}
// snippet-end:[ssm.JavaScript.Basics.hello]