Hi Team, I'm trying to call an AWS service using a...
# general
a
Hi Team, I'm trying to call an AWS service using aws-sdk inside
index.ts
. 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. 😐
b
You don't normally need to await anything. Pulumi can normally use promises as inputs. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/#Input
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, ...]) => ....)
a
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