Pulumi,如何导出来自异步函数的值?

Tig*_*yan 1 javascript export pulumi

在我的 Pulumi 项目中,在 index.ts 文件中我必须调用
const awsIdentity = await aws.getCallerIdentity({ async: true });

因此,出于这个原因,我必须将所有代码包装到async函数中。我的问题是文件末尾的导出变量。

async function go() {
...
  const awsIdentity = await aws.getCallerIdentity({ async: true });
  const accountId = awsIdentity.accountId;
...
  return {
    dnsZoneName: DNSZone.name,
    BucketID: Bucket.id,
    dbHardURL: DBHost.publicDns,
    devDbURL: publicDbAddress.fqdn,
  };
}
Run Code Online (Sandbox Code Playgroud)

我想要export这4个值。我不明白如何,但导出后面的代码(至少pulumi up显示执行结束时的值)。

const result = go();
export const dnsZoneName = result.then((res) => res.dnsZoneName);
Run Code Online (Sandbox Code Playgroud)

这个

我想我不能使用top-level-await

什么是明确的解决方案?

小智 5

对于任何看到这篇文章的人来说,异步入口点现在是 Pulumi 的一等公民,详细信息请参见此处

您可以使用与此类似的代码,Pulumi 会自动为您解决所有问题,无需为导出输出执行任何操作

export async function go() {
...
  const awsIdentity = await aws.getCallerIdentity({ async: true });
  const accountId = awsIdentity.accountId;
...
  return {
    dnsZoneName: DNSZone.name,
    BucketID: Bucket.id,
    dbHardURL: DBHost.publicDns,
    devDbURL: publicDbAddress.fqdn,
  };
}
Run Code Online (Sandbox Code Playgroud)