11/18/2019, 2:22 PM
Hi Team, I'm trying to call an AWS service using aws-sdk inside
. It returns a promise. How can I do:
const someAwsValue = await new AWS().someService().someMethod().promise();
or similar in index.ts? Or even:
Copy code
new AWS().someService().someMethod(params, (someAwsValue)=> {
   // do Pulumi things in here, referencing someAwsValue in scope
Pulumi won't let me wrap everything in a top-level async function without dying. I tried looking in the docs how to use aws-sdks or perform async things inside of a Pulumi project, not sure how to proceed. 😐


11/18/2019, 4:46 PM
You don't normally need to await anything. Pulumi can normally use promises as inputs.
If you need to do some transformations on it you can use:
Copy code
const someAttribute = pulumi.output(myPromise).apply(result => result.someAttribute)
and then it can be used:
Copy code
new aws.s3.Bucket('mybucket', {name: someAttribute})
if you have multiple promises/outputs you can use
pulumi.all([promise1, promise2,...]).apply(([resolved1, resolved2, ...]) => ....)


11/18/2019, 9:49 PM
Casting a promise to pulumi.output was exactly what I wanted! It worked, I can use an AWS SDK method natively now in my index.ts, thank you so much for the documentation and direction! :D