man*_*oni 5 amazon-s3 amazon-web-services typescript pulumi
我正在通过 pulumi typescript 创建一个 s3 存储桶,并希望在 EC2 用户数据中使用此存储桶来复制对象。以下是我的代码。
const bucket = new aws.s3.Bucket("bucket-name", {
acl: "private",
});
Run Code Online (Sandbox Code Playgroud)
我上传了一个index.html文件,这是EC2的用户数据:-
const userData =
`#!/bin/bash
sudo apt update -y
sudo apt install -y apache2 && sudo apt install -y awscli
aws s3 cp s3://`+pulumi.interpolate`${bucket.id}`+`/index.html /var/www/html/index.html
sudo systemctl start apache2`;
Run Code Online (Sandbox Code Playgroud)
我使用pulumi.interpolate${bucket.id}` 来调用存储桶 ID,但是当我在 EC2 上检查用户数据时,出现以下错误。
aws s3 cp s3://Calling [toString] on an [Output<T>] is not supported.
To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`
Run Code Online (Sandbox Code Playgroud)
谁能帮助我如何在脚本中调用存储桶名称?
您应该将interpolate所有字符串操作放在外面
const userData = pulumi.interpolate`#!/bin/bash
sudo apt update -y
sudo apt install -y apache2 && sudo apt install -y awscli
aws s3 cp s3://${bucket.id}/index.html /var/www/html/index.html
sudo systemctl start apache2`;
Run Code Online (Sandbox Code Playgroud)
如果您的代码,+操作会调用toString输出并导致错误。
| 归档时间: |
|
| 查看次数: |
3617 次 |
| 最近记录: |