@@ -364,6 +364,26 @@ export const getAppSyncApi = async (appSyncApiId: string, region: string) => {
364364 return await service . getGraphqlApi ( { apiId : appSyncApiId } ) . promise ( ) ;
365365} ;
366366
367+ export const waitForAllDataSourceRolesToExist = async ( appSyncApiId : string , region : string ) => {
368+ const service = new AppSync ( { region } ) ;
369+
370+ const roles : string [ ] = [ ] ;
371+ let token = undefined ;
372+ do {
373+ const result = await service . listDataSources ( { apiId : appSyncApiId , nextToken : token } ) . promise ( ) ;
374+ token = result . nextToken ;
375+ const sources = result . dataSources ?? [ ] ;
376+ for ( const dataSource of sources . values ( ) ) {
377+ if ( dataSource . serviceRoleArn ) {
378+ roles . push ( dataSource . serviceRoleArn ) ;
379+ }
380+ }
381+ } while ( token ) ;
382+
383+ const allRolesExist = roles . map ( ( role ) => waitForRoleToExist ( role , region ) ) ;
384+ return Promise . all ( allRolesExist ) ;
385+ } ;
386+
367387export const getCloudWatchLogs = async ( region : string , logGroupName : string , logStreamName : string | undefined = undefined ) => {
368388 const cloudWatchLogsClient = new CloudWatchLogs ( { region, retryDelayOptions : { base : 500 } } ) ;
369389
@@ -480,6 +500,11 @@ export const listAttachedRolePolicies = async (roleName: string, region: string)
480500 return ( await service . listAttachedRolePolicies ( { RoleName : roleName } ) . promise ( ) ) . AttachedPolicies ;
481501} ;
482502
503+ export const waitForRoleToExist = async ( roleName : string , region : string ) => {
504+ const service = new IAM ( { region } ) ;
505+ return await service . waitFor ( 'roleExists' , { RoleName : roleName } ) . promise ( ) ;
506+ } ;
507+
483508export const getPermissionsBoundary = async ( roleName : string , region ) => {
484509 const iamClient = new IAM ( { region } ) ;
485510 return ( await iamClient . getRole ( { RoleName : roleName } ) . promise ( ) ) ?. Role ?. PermissionsBoundary ?. PermissionsBoundaryArn ;
0 commit comments