微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cloudformation - 将参数传递给二级堆栈

如何解决Cloudformation - 将参数传递给二级堆栈

我正在尝试将一些参数传递给嵌套堆栈。

我目前的配置如下:

根模板:

Parameters:
  subnetIds:
    Description: The array of subnet IDs assigned to the lambdas
    Type: List<AWS::EC2::subnet::Id>
  SecurityGroupIds:
    Description: The array of Security Groups Assigned to the lambda functions
    Type: List<AWS::EC2::SecurityGroup::Id>

Resources:
 Myresource1:
    Type: 'AWS::Serverless::Application'
    Properties:
      Location: 'resource1/template.yaml'
      Parameters:
        subnetIds: !Join [',',!Ref subnetIds]
        SecurityGroupIds: !Join [',!Ref SecurityGroupIds]

一个嵌套堆栈:

Parameters:
  subnetIds:
    Description: The array of subnet IDs assigned to the lambdas
    Type: List<AWS::EC2::subnet::Id>
  SecurityGroupIds:
    Description: The array of Security Groups Assigned to the lambda functions
    Type: List<AWS::EC2::SecurityGroup::Id>

Resources:
  MySecondLevelResource:
    Type: 'AWS::Serverless::Application'
    Properties:
      Location: 'app/template.yaml'
      Parameters:
        subnetIds: !Ref subnetIds
        SecurityGroupIds: !Ref SecurityGroupIds

二级嵌套堆栈:

Parameters:
  subnetIds:
    Description: The array of subnet IDs assigned to the lambdas
    Type: CommaDelimitedList
  SecurityGroupIds:
    Description: The array of Security Groups Assigned to the lambda functions
    Type: CommaDelimitedList

使用此配置,当 AWS 尝试部署第一个嵌套堆栈时出现错误,因为它需要一个字符串或字符串对象。 我还尝试在第一级堆栈中使用 CommaDelimitedList 类型,但在第二级仍然出现错误。 到目前为止还没有运气。

有没有人遇到过这种情况或对如何解决有任何想法?

解决方法

首先,您的模板存在重大错误

SubnetIds: !Join [',',!Ref SecurityGroupIds]

使用 SecurityGroupIds 将导致失败,因为 SecurityGroupIds 不是 SubnetIds,不管其他任何问题。

嵌套堆栈也是使用 AWS::CloudFormation::Stack 创建的,它的语法与您使用的语法不同。因此,如果您实际上通过 AWS::CloudFormation::Stack 使用嵌套堆栈,则传递参数的方式是正确的

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。