0

是否可以引用另一个未输出的 CloudFormation 资源?

例如,在 file1.yaml

Resource:
  SG1:
    Type: AWS::EC2::SecurityGroup
    ....

在 file2.yaml 中,我需要引用 SG1

  SGMSKClusterIgress6:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      SourceSecurityGroupId: SG1 # How to reference SG1 here
      GroupId: !ImportValue MySecurityGroup
      IpProtocol: tcp
      FromPort: 443
      ToPort: 443

我知道Outputsfile1.yaml中是否有,例如,

Resource:
  SG1:
    Type: AWS::EC2::SecurityGroup
    ....
Outputs:
  SG1Output:
    Value: !Ref SG1
    Export:
      Name: File1SG1

我可以在 file2.yaml 中使用它

      SourceSecurityGroupId: !ImportValue File1SG1 # SG1 output name

不输出怎么办?我是否必须修改 file1.yaml 才能添加该Outputs部分并更新配置的产品?

4

1 回答 1

2

是的,对于在 CloudFormation 方面引用资源,您应该使用输出。如果您无权访问 file1.yaml,您可以在 file2.yaml 中创建一个参数,您可以在其中指定安全组 id 并在资源创建中引用它

于 2021-09-04T11:19:19.477 回答