【问题标题】:Getting Elasticache endpoint using pulumi Typescript使用 pulumi Typescript 获取 Elasticache 端点
【发布时间】:2022-08-16 03:35:28
【问题描述】:

使用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.\\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 主要端点,或者可以告诉我我在这里做错了什么,将不胜感激。

  • 我遇到了完全相同的问题。你能想出解决办法吗?据我所知,这个输出似乎被破坏了......
  • 我什至尝试使用 getter 稍后在代码中获取创建的弹性缓存资源,并且发生了同样的问题。这个问题似乎影响了aws.elasticache 类中的所有端点输出。

标签: typescript amazon-web-services redis pulumi


【解决方案1】:

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 2016-12-19
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    • 2012-03-30
    • 2022-04-29
    • 2023-04-08
    • 2020-05-12
    • 1970-01-01
    相关资源
    最近更新 更多