You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在CloudFormation中获取AWS::MSK::Configuration的最新版本号?

解决CloudFormation中MSK配置版本号硬编码问题

我在通过CloudFormation创建包含MSK配置并关联MSK集群的栈时遇到一个问题:创建AWS::MSK::Configuration资源后,只能获取到ARN,但关联MSK集群时同时需要ARN和版本号。目前把版本号硬编码为1,仅在首次创建栈时有效,后续更新配置后就会失效,求解决办法?

解决方案

  • 使用!GetAtt获取MSK配置的版本号:AWS::MSK::Configuration资源支持通过Revision属性获取当前配置的版本号,无需硬编码。
  • 在ConfigurationInfo的Revision字段直接引用该属性,无论配置是首次创建还是后续更新,集群都会自动关联最新的配置版本。

修正后的CloudFormation代码

...
  MSKConfiguration:
    Type: AWS::MSK::Configuration
    Properties:
      Name: aws-msk-configuration
      ServerProperties: |
        auto.create.topics.enable = true
        zookeeper.connection.timeout.ms = 1000
        log.roll.ms = 604800000

  MSKCluster:
    Type: AWS::MSK::Cluster
    Properties:
      ClusterName: !Ref ClusterName
      ClientAuthentication: !If
        - UsingIamAuthentication
        - Sasl:
            Iam:
              Enabled: true
        - Sasl:
            Scram:
              Enabled: true
      ConfigurationInfo:
        Arn: !GetAtt MSKConfiguration.Arn
        Revision: !GetAtt MSKConfiguration.Revision
...

补充说明

当你更新MSKConfiguration的ServerProperties内容时,CloudFormation会自动生成新的配置版本,!GetAtt MSKConfiguration.Revision会自动获取最新版本号,确保集群始终关联当前生效的配置版本,避免硬编码带来的兼容性问题。

内容的提问来源于stack exchange,提问作者webh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 20:50:29