使用 Pulumi 将随机后缀添加到 S3 存储桶名称
Random Suffix added to S3 Bucket name with Pulumi
当我使用 Pulumi 创建 S3 存储桶时,指定的存储桶名称会添加一个随机后缀。我怎样才能避免这种情况?
import * as aws from "@pulumi/aws";
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket");
// Export the name of the bucket
export const bucketName = bucket.id;
您可以在参数中明确指定存储桶名称:
new aws.s3.Bucket("my-bucket", { bucket: "my-bucket" });
对于 S3 存储桶的这种特定情况,Mikhail 的回答是正确的。更一般地说,这种行为是由于 Pulumi 中的 auto-naming 功能。来自 https://www.pulumi.com/docs/reference/programming-model/#autonaming:
This random postfix is added by default for two reasons. First, it ensures that two instances of a program can be deployed to the same environment without risk of name collisions. Second, it ensures that it will be possible to do zero-downtime replacements when needed, by creating the new resource first, updating any references to point to it, and then deleting the old resource.
通过在资源上显式设置 name
属性(或在 S3 存储桶的情况下为 bucket
),可以针对每个资源覆盖此行为。
当我使用 Pulumi 创建 S3 存储桶时,指定的存储桶名称会添加一个随机后缀。我怎样才能避免这种情况?
import * as aws from "@pulumi/aws";
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket");
// Export the name of the bucket
export const bucketName = bucket.id;
您可以在参数中明确指定存储桶名称:
new aws.s3.Bucket("my-bucket", { bucket: "my-bucket" });
对于 S3 存储桶的这种特定情况,Mikhail 的回答是正确的。更一般地说,这种行为是由于 Pulumi 中的 auto-naming 功能。来自 https://www.pulumi.com/docs/reference/programming-model/#autonaming:
This random postfix is added by default for two reasons. First, it ensures that two instances of a program can be deployed to the same environment without risk of name collisions. Second, it ensures that it will be possible to do zero-downtime replacements when needed, by creating the new resource first, updating any references to point to it, and then deleting the old resource.
通过在资源上显式设置 name
属性(或在 S3 存储桶的情况下为 bucket
),可以针对每个资源覆盖此行为。