https://pulumi.com logo
#general
Title
# general
e

elegant-crayon-4967

01/23/2020, 12:52 AM
Looking for help on a simple one here. I want to print out (first step, later I’ll pass the list) of aws accounts in our organization.
Copy code
const org = aws.organizations.getOrganization()
accounts
is a property of that, but I have no idea how to get to it or print out it’s promise
Copy code
const orgAccounts = aws.organizations.getOrganization();

orgAccounts.accounts.forEach(account => {
  console.log(account)
});
^ I thought would work, but get the error
TypeError: Cannot read property 'forEach' of undefined
h

handsome-truck-95168

01/23/2020, 1:05 AM
Are you familiar with JavaScript promises?
e

elegant-crayon-4967

01/23/2020, 1:06 AM
trying to be, definitely my biggest challenge from a python background
I did just create this
Copy code
(async () => {
  const orgs = await aws.organizations.getOrganization();
  orgs.accounts.forEach(account => 
    console.log(account))
})()
but there has to be a more elegant way to do this
h

handsome-truck-95168

01/23/2020, 5:08 PM
If that is at top-level (not in a function, module), then unfortunately that's the best way to do it. Nice work!
3 Views