1

我正在尝试在堆栈中创建两个单独的存储桶,但是当我尝试将文件写入第二个存储桶时,它与第一个存储桶中的任何文件同名,但出现错误 error: Duplicate resource URN 'urn:pulumi:dev::quickstart::aws:s3/bucketObject:BucketObject::index.html'; try giving it a unique name

下面的代码演示了这个问题。

显然,就 AWS 而言,没有冲突,但是我应该定义一个不同的“名称”来防止 Pulumi 创建看似重复的密钥吗?

using Pulumi;
using Pulumi.Aws.S3;

class MyStack : Stack
{
    public MyStack()
    {
        // Create an AWS resource (S3 Bucket)
        var bucket1 = new Bucket("my-bucket");

        var bucketObject1 = new BucketObject("index.html", new BucketObjectArgs {
            Bucket = bucket1.BucketName,
            Content = "HTML in 1"
        });

        var bucket2 = new Bucket("my-bucket2");

        var bucketObject2 = new BucketObject("index.html", new BucketObjectArgs {
            Bucket = bucket2.BucketName,
            Content = "HTML in 2"
        });
    }
}
4

1 回答 1

1

您应该为所有资源提供唯一的逻辑名称,包括两个BucketObject's。Pulumi 使用逻辑名称来标识堆栈中的资源。

您仍然可以为两个文件提供相同的物理名称:

var bucketObject1 = new BucketObject("b1-index.html", new BucketObjectArgs {
    Key = "index.html",
    Bucket = bucket1.BucketName,
    Content = "HTML in 1"
});

var bucketObject2 = new BucketObject("b2-index.html", new BucketObjectArgs {
    Key = "index.html",
    Bucket = bucket2.BucketName,
    Content = "HTML in 2"
});
于 2020-10-09T13:24:49.983 回答