【问题标题】:No export name XYZ found in serverless framework在无服务器框架中找不到导出名称 XYZ
【发布时间】:2021-04-18 08:51:37
【问题描述】:
functions:
  wsConnect:
    handler: src/handlers/wsConnect.handler
    name: ${self:provider.stage}-wsConnect
    environment:
      WS_SERVICE: ${self:provider.stage}-wsService
    events:
      - websocket:
          route: $connect
  wsDisconnect:
    handler: src/handlers/wsDisconnect.handler
    name: ${self:provider.stage}-wsDisconnect
    environment:
      WS_SERVICE: ${self:provider.stage}-wsService
    events:
      - websocket:
          route: $disconnect
  wsDefault:
    handler: src/handlers/wsDefault.handler
    name: ${self:provider.stage}-wsDefault
    events:
      - websocket:
          route: $default
resources:
    Outputs:
        ExportedWebSocketpi:
          Value: !Ref WebsocketsApi # Logical ID
          Export:
            Name: webSocketAPI
        ExportedRestApi:
          Value: !Ref ApiGatewayRestApi # Logical ID
          Export:
            Name: rest-wsAPI
custom:
  importwebSocketAPI:
    Fn::ImportValue: webSocketAPI

我已经创建了这个 WebSocket 并尝试第一次部署它,它显示 No export name webSocketAPI found, custom: tag is executed before output export the API。我该如何使用 DependsOn 或有其他方法可以做到这一点?

【问题讨论】:

    标签: yaml amazon-cloudformation serverless-framework


    【解决方案1】:

    您缺少输出的必填字段 - value

    您可以在这里找到如何设置Outputs in serverless framework

    另一个例子:

    resources:
        Outputs:
            DBUserName:
                Value: ${self:custom.dbCredentials.DB_USERNAME}
            DBPassword:
                Value: ${self:custom.dbCredentials.DB_PSW}
    
            RDSClusterID:
                Description: "RDS Cluster"
                Value: { Ref: RDSCluster }
    
            CognitoUserPoolId:
                Value: ${self:custom.userPool}
    

    【讨论】:

    • 请查看我更新的代码。即使这个代码给出了同样的问题。为什么,因为它custom: TAG 没有等待资源完成。
    • 自定义标签从 AWS CloudFormation 变量中读取/导入值 webSocketAPIwebSocketAPI 是从同一个堆栈中导出的。因此,您会得到一种循环依赖,您尝试读取尚未创建的内容。在你的 serverless.yml 配置中直接阅读WebsocketsApi,你不需要导出/导入变量。
    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 2016-06-18
    • 2020-09-25
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    相关资源
    最近更新 更多