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

有没有人经历过这种情况或关于如何解决它的任何想法?

标签: parametersamazon-cloudformationaws-samnested-stack

解决方案


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

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

使用SecurityGroupIds将导致失败 as SecurityGroupIdsare not SubnetIds,不管任何其他问题。

嵌套堆栈也是使用AWS::CloudFormation::Stack创建的,它的语法与您使用的不同。因此,如果您实际上是通过AWS::CloudFormation::Stack.


推荐阅读