Looking for help on a simple one here. I want to p...
# general
e
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
Are you familiar with JavaScript promises?
e
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
If that is at top-level (not in a function, module), then unfortunately that's the best way to do it. Nice work!