【问题标题】:How can I split the appsync into multiple stack?如何将 appsync 拆分为多个堆栈?
【发布时间】:2020-11-22 11:08:58
【问题描述】:

我有一个项目要使用此插件 (https://github.com/sid88in/serverless-appsync-plugin) 部署 appsync API。我正在寻找一种拆分所有基础设施的解决方案。分成多个堆栈(多个 serverless.yml 文件)。

我的项目结构如下:

main/serverless.yml
dataSources/serverless.yml
resolvers/serverless.yml
schema/serverless.yml

main 文件夹仅部署 Appsync 实例以及日志记录和身份验证。它不包括任何架构、解析器等。

以及其他文件夹,每个文件夹都是将schema、resolvers、dataSources部署到主文件夹部署的Appsync。在这些文件夹中,他们需要导入 appsync 基础设施才能附加这些解析器。

这意味着将创建多个 cloudformation 堆栈并在其中使用跨堆栈引用。我想知道如何使用这个插件来做到这一点。

【问题讨论】:

    标签: amazon-web-services serverless aws-appsync


    【解决方案1】:

    一般而言,您可以使用Output 导出其他堆栈中可能需要的 CF 变量,例如:

     resources:
       Resources:
         NotesTable:
           Type: AWS::DynamoDB::Table
           Properties:
             TableName: notes
    
     # ...
    
      Outputs:
        Value:
          Ref: NotesTable
        Export:
          Name: NotesTableName
    

    在另一个文件中读取它们:'Fn::ImportValue': NotesTableName

    我使用的示例来自一个很好的来源: https://serverless-stack.com/chapters/cross-stack-references-in-serverless.html

    您的示例是 AppSync...

    您可以在专用堆栈中定义数据源(例如 DynamoDb),并且在 AppSync 源中只需按名称引用它们,例如:

    - type: AMAZON_DYNAMODB
      name: ItemSource
      description: Item table
      config:
        tableName: ItemTable // Whatever name you used in your DynamoDb stack
    

    对于 lambda,您将使用输出/导入。在解析器中:

    - type: AWS_LAMBDA
      name: SomeLambdaSource
      config:
        functionName: someSource
        lambdaFunctionArn:
          Fn::ImportValue: SomeLambdaSource
    

    在您的 lambda 堆栈中:

    functions:
      someSource:
        name: SomeSource
        handler: src/handlers/someSource.handler
     
    
    resources:
      Outputs:
        SomeSource:
          Value:
            Fn::GetAtt:
              - SomeSource
              - Arn
          Export:
            Name: SomeSource
    

    【讨论】:

    • 感谢您的回答。我可以将 appsync 架构拆分为多个堆栈吗?
    • 我不这么认为。即使将源移动到另一个堆栈后,您是否也遇到了限制?
    猜你喜欢
    • 1970-01-01
    • 2018-04-21
    • 2017-12-15
    • 1970-01-01
    • 2021-03-12
    • 2015-07-02
    • 1970-01-01
    • 2010-12-05
    • 2012-10-20
    相关资源
    最近更新 更多