serverless-appsync-plugin icon indicating copy to clipboard operation
serverless-appsync-plugin copied to clipboard

How can I split the appsync into multiple stack?

Open zhaoyi0113 opened this issue 3 years ago • 7 comments

First of all, thanks a lot for releasing this awesome plugin. I have a question about how to split the appsync into multiple stack?

My project structure looks like:

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

The main folder only deploys the Appsync instance and logging and authentication. It doesn't include any schema, resolvers etc.

And other folders each of which is to deploy schema, resolvers, dataSources to the Appsync deployed by the main folder. In these folders, they need to import the appsync arn in order to attach these resolvers.

That means there will be multiple cloudformation stacks created and using cross stack reference among them. I wonder how I can make this by using this plugin.

zhaoyi0113 avatar Aug 02 '20 01:08 zhaoyi0113

Hi @zhaoyi0113 are you doing this intentionally in order to split concerns or is it due to the CloudFormation restriction on stack size?

For the Cfn restrictions, there is this plugin

Otherwise, you should be good by referencing the ARN's as you suggested. You can probably do that using Output references from serverless.

By default, this plugin outputs:

  • The Api url
  • Api Id
  • Api Key

See here

But you can manually output any resource.

bboure avatar Aug 02 '20 07:08 bboure

I am doing it intentionally not because of 200 resources limitation. I'd like to control each stack resources. I know it exports these values but how can I use these values in this plugin? The only way I can think of is to create resolvers, datasource via Cloudformation. Is there a way to attach resolvers to an existing appsync via this plugin?

zhaoyi0113 avatar Aug 02 '20 08:08 zhaoyi0113

@zhaoyi0113 I think I know what you mean now.

The only thing you can really separate are the data sources (Lambda functions, Dynamodb tables, etc) Then, you can reference them in the datasource config:

     - type: AMAZON_DYNAMODB
        name: myDynamo
        config:
          tableName:
            'Fn::ImportValue': MyDynamoDbName
    - type: AWS_LAMBDA
        name: myLambda
        config:
          lambdaFunctionArn:
            'Fn::ImportValue': MyFunctionArn

What you cannot do is separate the mapping template and datasource definitions from the AppSync definition.

In other words, everything under custom.appSync MUST go into the same stack.

bboure avatar Aug 02 '20 09:08 bboure

right, that's what my concern really is. If I want to separate the definition, I will have to use cloudformation Resources, like:

resources:
    Resources:
        Resources:
           myDataSource:
          Type: AWS::AppSync::DataSource
          Properties:
             Name: myDataSource
            ApiId:
                Fn::ImportValue: !Sub '${appsyncStackName}-graphQlApiId'
           Type: AWS_LAMBDA
        ...

and in above settings, the ApiId is imported from the appsync stack.

zhaoyi0113 avatar Aug 02 '20 10:08 zhaoyi0113

All right, I understand. This is not something we support right now. However I guess we could consider this feature. This could probably help too with other issues like #194

bboure avatar Aug 02 '20 13:08 bboure

@zhaoyi0113 Would you feel like opening a PR yourself to solve this particular issue? Since you have a real use-case, and understand the problem well, it might help finding the best approach.

bboure avatar Aug 02 '20 13:08 bboure

@bboure Thanks for confirming that. I will see what the best solution for that.

zhaoyi0113 avatar Aug 02 '20 23:08 zhaoyi0113