gpt4 book ai didi

typescript - 使用 pulumi Typescript 获取 Elasticache 端点

转载 作者:行者123 更新时间:2023-12-05 05:47:56 25 4
gpt4 key购买 nike

使用 Pulumi 我正在尝试从 elasticache 集群获取主要端点,以便我可以将其作为环境变量传递给 fargate aws 上的服务。出于某种原因,适用于 RDS 的相同过程不适用于 ElastiCache

pulumi version
v3.23.0
"@pulumi/aws": "^4.36.0",
"@pulumi/awsx": "^0.32.0",
"@pulumi/pulumi": "^3.23.0",

以下内容非常适合 RDS:

    super("backend:portalInfrastructure:rds", name, {}, opts)

let securityGroupIds = cluster.securityGroups.map((g:any) => g.id)

let dbSubnets = new aws.rds.SubnetGroup(`${name}-rds-subnets-${ENV_LOWER}`, {
subnetIds: vpc.publicSubnetIds,
})

//Extra dash on the name here because pulumi doesn't add one for RDS
let db = new aws.rds.Instance(`${name}-postgres-${ENV_LOWER}-`, {
engine: 'postgres',
instanceClass: 'db.t3.micro',
allocatedStorage: 20,
dbSubnetGroupName: dbSubnets.id,
vpcSecurityGroupIds: securityGroupIds,
// TODO only needs to be publicly accessible
// to run migrations from external host
publiclyAccessible: true,
...DB_CONN,
tags: {
'env':ENV_LOWER
},

skipFinalSnapshot: true
})

this.DBSetupOutput = {
dbhost : db.endpoint.apply(e => e.split(":")[0]),
db: db
}

// For dependency tracking, register output properties for this component
this.registerOutputs({
DBSetupOutput: this.DBSetupOutput
})

然而,当我为 ElastiCache/Redis 尝试此操作时:

    super("backend:portalInfrastructure:redis", name, {}, opts)

let securityGroupIds = cluster.securityGroups.map((g:any) => g.id)

let redisSubnets = new aws.elasticache.SubnetGroup(`${name}-redis-subnets-${ENV_LOWER}`, {
subnetIds: vpc.publicSubnetIds,
})

let redis = new aws.elasticache.Cluster(`${name}-redis-${ENV_LOWER}`, {
engine: "redis",
engineVersion: "3.2.10",
nodeType: "cache.t3.micro",
numCacheNodes: 1,
parameterGroupName: "default.redis3.2",
port: 6379,
subnetGroupName: redisSubnets.id,
securityGroupIds: securityGroupIds
}, {parent: this});

redis.clusterAddress.apply(address => {
console.log(address)
})

this.RedisSetupOutput = {
redishost : redis.clusterAddress.apply(a => a),
redis: redis
}

// For dependency tracking, register output properties for this component
this.registerOutputs({
RedisSetupOutput: this.RedisSetupOutput
})

我的变量 redishost 得到以下输出

"Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `prefix${v}suffix`)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee https://pulumi.io/help/outputs for more details.\nThis function may throw in a future version of @pulumi/pulumi."

我不明白,因为我正在调用 apply 到 pulumi 输出。尝试获取 ElastiCache clusterAddresscacheNodes 时也会发生同样的事情。如果有人了解如何获取 ElastiCache 主要端点,或者可以告诉我我在这里做错了什么,将不胜感激。

最佳答案

您正在创建一个 redis elasticache 集群。如果您阅读 elasticache 的文档,它会指出 clusterAddress 仅为 memcache 集群填充。参见 here

您实际需要使用的是 cacheNodes 输出,如下所示:

this.RedisSetupOutput = {
redishost : redis.cacheNodes
redis: redis
}

这将返回一个地址数组,您可以通过指定一个数组的输出来缩小范围:

this.RedisSetupOutput = {
redishost : redis.cacheNodes[0].address
redis: redis
}

关于typescript - 使用 pulumi Typescript 获取 Elasticache 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70900831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com