简体   繁体   中英

How to include a graphql schema file into an AWS Cloudformation template?

I am creating a simple AWS Cloudformation template file for an AppSync API. I would like to create the GraphQL schema in a separate file and reference it from the stack template but have been unable to do so.

The stack template is in a file template.yaml . The following snippet defines the GraphQL schema:

  GraphQLSchema:
    Type: AWS::AppSync::GraphQLSchema
    Properties: 
      ApiId: !GetAtt AppSyncAPI.ApiId
      DefinitionS3Location: schema.graphql

The GraphQL schema is in the same directory called in a separate file called schema.graphql .

schema {}

When in use the aws-cli to create the stack, the following error message appears in the Cloudformation events log when creating the GraphQLSchema:

"S3 location not valid for DefinitionS3Location"

How do I reference a local file for the schema and have the aws-cli automatically bundle it together?

It's not possible. There are only two options:

  1. Create a script to upload your GraphQL schema to S3 automatically and reference at DefinitionS3Location or

  2. create your GraphQL schema directly in your CloudFormation template:

AppSyncGraphQLSchema:
    Type: AWS::AppSync::GraphQLSchema
    DependsOn: AppSyncGraphQLApi
    Properties:
      ApiId: !GetAtt AppSyncGraphQLApi.ApiId
      Definition: |
        ...
        schema {
          query: Query
          mutation: Mutation
        }
        ...

aws cloudformation create-stack will not work with a locally referenced schema.

First, package the files with aws cloudformation package which uploads the schema to the designated S3 bucket and replaces the local reference with the S3 bucket reference in the generated package. Then that package can be deployed using aws cloudformation deploy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM