redis 使用pulumi Typescript获取弹性缓存端点

wbrvyc0a  于 2022-10-31  发布在  Redis
关注(0)|答案(1)|浏览(153)

使用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输出。同样的事情发生在试图获得ElastiCacheclusterAddresscacheNodes时。如果有人知道如何获得ElastiCache主要端点,或者能告诉我我在这里做错了什么,我将非常感激。

t8e9dugd

t8e9dugd1#

您正在创建一个redis elasticache集群。如果您阅读了elasticache的文档,它会指出clusterAddress只为memcache集群填充。请参阅此处
实际上,您需要使用的是cacheNodes输出,如下所示:

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

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

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

相关问题