我正在处理创建 AWS API 网关。我正在尝试创建 CloudWatch Log 组并将其命名为API-Gateway-Execution-Logs_${restApiId}/${stageName}。我在 Rest API 创建方面没有问题。
我的问题是将类型为 pulumi.Outout 的 restApi.id 转换为字符串。
我已经尝试了在他们的PR#2496中提出的这两个版本
const restApiId = apiGatewayToSqsQueueRestApi.id.apply((v) => `${v}`);const restApiId = pulumi.interpolate `${apiGatewayToSqsQueueRestApi.id}` 这是使用它的代码
const cloudWatchLogGroup = new aws.cloudwatch.LogGroup(
`API-Gateway-Execution-Logs_${restApiId}/${stageName}`,
{},
);
Run Code Online (Sandbox Code Playgroud)
stageName 只是一个字符串。
我也试过apply再次喜欢
const restApiIdStrign = restApiId.apply((v) => v);
我总是从 pulumi up
aws:cloudwatch:LogGroup API-Gateway-Execution-Logs_Calling [toString] on an [Output<T>] is not supported.
请帮我将输出转换为字符串
假设我想在单个 JS 模块中导出一些通过调用某个异步函数获得的值。使导出等待结果/Promise 解决的机制是什么?
作为示例代码片段,我将其放在这里
function go() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("Success!"), 3000);
});
}
let AS;
go().then((x) => {
AS = x;
});
module.exports = AS;
Run Code Online (Sandbox Code Playgroud)
该函数可以发出任何 API 请求。我不想导出整个函数并在其他模块中调用它。
在我的 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。
什么是明确的解决方案?