【问题标题】:Cloudformation - Passing Parameters to second level stackCloudformation - 将参数传递到二级堆栈
【发布时间】:2023-03-18 06:02:01
【问题描述】:

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

我目前的配置如下:

根模板:

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 类型,但在第二级仍然出现错误。 到目前为止还没有运气。

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

【问题讨论】:

    标签: parameters amazon-cloudformation aws-sam nested-stack


    【解决方案1】:

    首先,您的模板中有一个重大错误

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

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

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

    【讨论】:

    猜你喜欢
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 2022-01-19
    • 1970-01-01
    • 2021-05-11
    • 2016-07-10
    • 1970-01-01
    相关资源
    最近更新 更多