@@ -26,23 +26,37 @@ async function onEvent(event: CloudFormationCustomResourceEvent) {
2626async function onCreate ( event : CloudFormationCustomResourceEvent ) {
2727 const memberAccounts = event . ResourceProperties . memberAccounts ;
2828
29- const memberParams = {
30- AccountDetails : memberAccounts ,
31- } ;
3229 // Creating Members
33- console . log ( `Creating Members for "${ memberParams } "` ) ;
30+ console . log ( `Creating Members for "${ memberAccounts } "` ) ;
3431 const accountIds : string [ ] = [ ] ;
35- await throttlingBackOff ( ( ) => hub . createMembers ( memberParams ) . promise ( ) ) ;
36- for ( const account of memberAccounts ) {
37- accountIds . push ( account . AccountId ) ;
32+
33+ //Security Hub will only process 50.
34+ const pageSize = 50 ;
35+ for ( let i = 0 ; i < memberAccounts . length ; i += pageSize ) {
36+ const currentPage = memberAccounts . slice ( ) . splice ( i , pageSize ) ;
37+ const pagedMemberParams = {
38+ AccountDetails : currentPage ,
39+ } ;
40+ console . log ( `Creating Members (paged) for "${ pagedMemberParams } "` ) ;
41+ const createResponse = await throttlingBackOff ( ( ) => hub . createMembers ( pagedMemberParams ) . promise ( ) ) ;
42+ console . log ( `Create Sub Accounts Response "${ JSON . stringify ( createResponse ) } ""` ) ;
43+ for ( const account of currentPage ) {
44+ accountIds . push ( account . AccountId ) ;
45+ }
3846 }
3947
40- const params = {
41- AccountIds : accountIds ,
42- } ;
4348 console . log ( `Inviting Members for "${ accountIds } "` ) ;
44- const inviteResponse = await throttlingBackOff ( ( ) => hub . inviteMembers ( params ) . promise ( ) ) ;
45- console . log ( `Invite Sub Accounts Response "${ inviteResponse } "` ) ;
49+
50+ //Security Hub will only process 50.
51+ for ( let i = 0 ; i < accountIds . length ; i += pageSize ) {
52+ const currentPage = accountIds . slice ( ) . splice ( i , pageSize ) ;
53+ const pagedParams = {
54+ AccountIds : currentPage ,
55+ } ;
56+ console . log ( `Inviting Members (paged) for "${ pagedParams } "` ) ;
57+ const inviteResponse = await throttlingBackOff ( ( ) => hub . inviteMembers ( pagedParams ) . promise ( ) ) ;
58+ console . log ( `Invite Sub Accounts Response "${ JSON . stringify ( inviteResponse ) } "` ) ;
59+ }
4660}
4761
4862async function onUpdate ( event : CloudFormationCustomResourceEvent ) {
0 commit comments