title: Correct way to use AWS SDK within AWS CDK
body: <p>I'm trying to use the SDK within my CDK application. My stack is creating a directory, some networking stuff, then some instances which it joins to the domain using a PowerShell script which requires the AD DNS IPs, I'm currently using it like so:</p>
  
  <pre><code>const ds = new DirectoryService();
  
  const result = new Promise(function (resolve: (value: string) =&gt; any, reject) {
          ds.describeDirectories({}, function (err, data) {
              if (err){
              reject(data)
          }else{
              try{
                  if (data.DirectoryDescriptions){
                      if (data.DirectoryDescriptions[0].DnsIpAddrs){
                          resolve(data.DirectoryDescriptions[0].DnsIpAddrs.toString())
                      }
                  }
              }catch (e) {
                  reject("Directory doesn't exist yet.")
              }
          }
      })
  });
  result.then(value =&gt; {
      const subs = {
          "#{DNS_ADDRESSES}": value,
          "#{SECRET_ID}": directory.directorySecret.secretArn
      };
  
      Object.entries(subs).forEach(
          ([key, value]) =&gt; {
              domainJoinScript = domainJoinScript.replace(key, String(value));
          }
      );
  
      new  Stack(app, 'instances', networking.vpc, domainJoinScript);
  
  }).catch(error =&gt; {
      print(error)
  });
  </code></pre>
  
  <p>Now this works, but it's far from a clean solution. My new Stack has multiple resources within it which means I have to pass the result of the SDK call through several levels, instead of just directly where it's needed, and if I had to make multiple SDK calls this would get even messier.</p>
  
  <p>The core problem is the AWS SDK being purely asynchronous in JS, which means I have to use the fairly verbose pattern above to wrap it.</p>
  
  <p>Does anyone have a better way to do this?</p>