我创建了一个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
没运气!!!
同样,ImportValue函数不能包含依赖于资源的
Ref
或GetAtt
函数。
和:
当它包含
!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