使用pulumi Typescript获取Elasticache端点



使用Pulumi,我试图从elasticache集群获取主端点,以便将其作为环境变量传递给aws上的fargate服务。由于某些原因,适用于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.nnTo 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`nnSee https://pulumi.io/help/outputs for more details.nThis function may throw in a future version of @pulumi/pulumi."

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

您正在创建一个redi-elasticache集群。如果您阅读了elasticache的文档,它指出clusterAddress仅为memcache集群填充。参见此处

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

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

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

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

最新更新