import * as fs from "fs-extra" ; import * as _ from "lodash" ; import * as path from "path" ; export const waitForStatus = async ( requestParams , serverlessProps , retryCount = 0 ) => { const { awsProvider , serverless } = serverlessProps ; const { awsMethod , callbackMethod , methodParams , statusPath } = requestParams ; try { const resourceStatus = await awsProvider . request ( "CloudFormation" , awsMethod , methodParams ) ; const status = _ . get ( resourceStatus , statusPath ) ; if ( status . includes ( "FAILED" ) || retryCount > 120 ) { throw new Error ( ) ; } else if ( status === "CREATE_COMPLETE" ) { serverless . cli . log ( "Resource successfully created." ) ; callbackMethod ( ) ; return ; } setTimeout ( ( ) => waitForStatus ( requestParams , serverlessProps , retryCount + 1 ) , 30000 ) ; } catch ( stackErr ) { serverless . cli . log ( `Something went wrong while creating aws resource: ${ stackErr }` ) ; } } ; export const fetchPolicy = async ( templatePolicy ) => { const policy = await fs . readFile ( path . resolve ( __dirname , ".." , "templates" , templatePolicy ) , "utf-8" ) ; return policy ; } ;