将同名文件写入两个S3存储桶时出现错误“错误:资源URN重复”

时间:2020-10-09 13:19:03

标签: pulumi

我正在尝试在堆栈中创建两个单独的存储桶,但是当我尝试将文件写入与第二个存储桶同名的文件时,出现错误 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"
        });
    }
}

1 个答案:

答案 0 :(得分:0)

您应该为所有资源(包括两个BucketObject)赋予唯一的逻辑名称。 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"
});