使用Pulumi
,我尝试从elasticache
群集获取主端点,以便将其作为环境变量传递给aws
上的fargate
服务。由于某种原因,适用于RDS
的相同过程在ElastiCache
上不起作用。
第一个
下面的代码对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
clusterAddress
或cacheNodes
时。如果有人知道如何获得ElastiCache
主要端点,或者能告诉我我在这里做错了什么,我将非常感激。
1条答案
按热度按时间t8e9dugd1#
您正在创建一个redis elasticache集群。如果您阅读了elasticache的文档,它会指出
clusterAddress
只为memcache
集群填充。请参阅此处实际上,您需要使用的是
cacheNodes
输出,如下所示:这将返回一个已寻址的数组,您可以通过从数组中指定一个输出来缩小范围: