使用Cloudformation堆栈中的连接导入值

问题描述 投票:2回答:1

我创建了一个VPC堆栈,它导出VPC id,私有和公有子网组等值。我正在尝试使用ImportValue, Join and Ref的简写符号构建一个字符串。任何帮助都赞赏使这个表达工作。

MyDBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: Subnets available for the RDS DB Instance
      SubnetIds: !ImportValue !Join [ '-', [ !Ref VPCStackName, 'private-subnets' ]]
      Tags:
      - Key: Service
        Value: !Ref ResourceTag

我收到的错误很明显:

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: YAML not well-formed. (line 87, column 29)

试过的事情如:

MyDBSubnetGroup:
        Type: AWS::RDS::DBSubnetGroup
        Properties:
          DBSubnetGroupDescription: Subnets available for the RDS DB Instance
          SubnetIds: !ImportValue
            - Fn::Join
              - '-'
              - - !Ref VPCStackName
              - 'vpcid'
          Tags:
          - Key: Service
            Value: !Ref ResourceTag

没运气!!!

amazon-web-services amazon-cloudformation
1个回答
1
投票

来自documentation

同样,ImportValue函数不能包含依赖于资源的RefGetAtt函数。

和:

当它包含!ImportValue时,你不能使用短形式的!Sub

(因为它会导致YAML无效)

如果VPCStackName是参数,并且您要导出逗号分隔值,则可以执行以下操作:

MyDBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: Subnets available for the RDS DB Instance
      SubnetIds:
        Fn::Split: # Split to get a list of strings
          - ","
          - Fn::ImportValue: # Use full function name
              !Sub "${VPCStackName}-private-subnets" # Substitute parameter
      Tags:
      - Key: Service
        Value: !Ref ResourceTag
© www.soinside.com 2019 - 2024. All rights reserved.