AWS CloudFormation 忽略现有资源

AWS CloudFormation ignore an existing resource

我在 CloudFormation 中创建了一个堆栈,我需要帮助来改进它。 在下面的堆栈中,我有一个 VPC 端点,但无法创建它两次,也就是说,我不能有两个相同的服务名称。 有没有人知道创建一个条件,如果创建了 VPC 端点,它会跳过此步骤?

  VPCEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      ServiceName: !Join
        - ''
        - - com.amazonaws.
          - !Ref 'AWS::Region'
          - .execute-api
      PrivateDnsEnabled: true
      SecurityGroupIds: 
        - !Ref 9SecurityGroupId
      SubnetIds: 
        Ref: 8SubnetIds
      VpcEndpointType: Interface
      VpcId: 
        Ref: 7VpcId
  
  APIGateway:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: !Ref 1Name
      EndpointConfiguration:
        Types:
          - PRIVATE
        VpcEndpointIds:
          - !Ref VPCEndpoint
      Policy:
        Statement:
          - Action: 'execute-api:Invoke'
            Effect: Allow
            Principal: '*'
            Resource: 'execute-api:/*'
          - Action: 'execute-api:Invoke'
            Condition:
              StringNotEquals:
                'aws:SourceVpce': !Ref VPCEndpoint
            Effect: Deny
            Principal: '*'
            Resource: 'execute-api:/*'
        Version: 2012-10-17

Does anyone have any idea to create a condition that if the VPC Endpoint is created it skips this step?

是的,如果您希望预先存在的资源检测完全自动化,您必须创建 macro or custom resource

否则,您可以只为您的模板创建一个输入参数,例如ShouldCreateTheInterfaceEndpoint。然后在部署模板时将其设置为 falsetrue