sid88in / serverless-appsync-plugin

serverless plugin for appsync
MIT License
950 stars 186 forks source link

TypeError: Cannot read properties of undefined (reading 'schema') #610

Open JonnyOrtiz-source opened 1 year ago

JonnyOrtiz-source commented 1 year ago

Below I'll show the complete error message I get when attempting sls deploy of my serverless.yml file that's also below. I've read through the plugin documentation and googled the error message but not finding anything to resolve the error. I'd appreciate any insight.

jonnyortiz@MacBook-Air backend % sls deploy
Running "serverless" from node_modules

Deploying serverless-appsync-backend to stage dev (us-east-1)
Warning: Invalid AppSync Configuration:
     at appSync: must be object

✖ Stack serverless-appsync-backend-dev failed to deploy (0s)
Environment: darwin, node 18.1.0, framework 3.33.0 (local) 3.33.0v (global), plugin 6.2.3, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
TypeError: Cannot read properties of undefined (reading 'schema')
    at getAppSyncConfig (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless-appsync-plugin/lib/getAppSyncConfig.js:45:39)
    at ServerlessAppsyncPlugin.loadConfig (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless-appsync-plugin/lib/index.js:1122:62)
    at _this.hooks.<computed> (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless-appsync-plugin/lib/index.js:363:23)
    at PluginManager.runHooks (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:530:15)
    at PluginManager.invoke (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:563:20)
    at async PluginManager.spawn (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:585:5)
    at async before:deploy:deploy (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/plugins/deploy.js:40:11)
    at async PluginManager.runHooks (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:563:9)
    at async PluginManager.run (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/lib/serverless.js:179:5)
    at async /Users/jonnyortiz/Google Drive/PERSONAL/UdemyAWSserverlessApps/serverless-appsync-demo/backend/node_modules/serverless/scripts/serverless.js:834:9
jonnyortiz@MacBook-Air backend %

Here's my serverless.yml

service: serverless-appsync-backend

frameworkVersion: "3"

plugins:
   - serverless-appsync-plugin

provider:
   name: aws
   runtime: nodejs18.x
   stage: dev
   region: us-east-1

custom:
   appSync:
      name: serverless-appsync-backend-dev
      mappingTemplates:
         - type: Query
           field: getBookById
           dataSource: booksTable
         - type: Mutation
           field: createBook
           dataSource: booksTable
      schema: schema.graphql
      dataSources:
         - type: AMAZON_DYNAMODB
           name: booksTable
           config:
              tableName: { Ref booksTable }
      authenticationType: AMAZON_COGNITO_USER_POOLS
      userPoolConfig:
         awsRegion: us-east-1
         defaultAction: ALLOW
         userPoolId: { Ref cognitoUerPool }

resources:
   Resources: ${file(resources.yml)}

Here's the resources.yml file

# Books table
booksTable:
   Type: AWS::DynamoDB::Table
   Properties:
      AttributeDefinitions:
         - AttributeName: "bookId"
           AttributeType: "S"
      BillingMode: PAY_PER_REQUEST
      KeySchema:
         - AttributeName: "bookId"
           KeyType: "HASH"
      Tags:
         - Key: "Name"
           Value: "books-table"

# Orders table
orderTable:
   Type: "AWS::DynamoDB::Table"
   Properties:
      AttributeDefinitions:
         - AttributeName: "userId"
           AttributeType: "S"
         - AttributeName: "orderId"
           AttributeType: "S"
         - AttributeName: "bookId"
           AttributeType: "S"
         - AttributeName: "createdAt"
           AttributeType: "S"
      BillingMode: "PAY_PER_REQUEST"
      KeySchema:
         - AttributeName: "userId"
           KeyType: "HASH"
         - AttributeName: "orderId"
           KeyType: "RANGE"
      GlobalSecondaryIndexes:
         - IndexName: "byOrder"
           KeySchema:
              - AttributeName: "bookId"
                KeyType: "HASH"
              - AttributeName: "createdAt"
                KeyType: "RANGE"
           Projection:
              ProjectionType: "ALL"
      Tags:
         - Key: "Name"
           Value: "order-table"

# Cognito User Pool
cognitoUserPool:
   Type: AWS::Cognito::UserPool
   Properties:
      UsernameAttributes:
         - email
      UserPoolName: YoutubeBookstoreUserPool

# Cognito User Pool Client
cognitoUserPoolClient:
   Type: AWS::Cognito::UserPoolClient
   Properties:
      ClientName: Web
      UserPoolId: !Ref cognitoUserPool

# Cognito User Pool Admin Group
cognitoAdminGroup:
   Type: AWS::Cognito::UserPoolGroup
   Properties:
      Description: "Admin users belong to this group"
      GroupName: "admin"
      Precedence: 0
      RoleArn: !GetAtt cognitoAdminIAMRole.Arn
      UserPoolId: !Ref cognitoUserPool

# Cognito Admin IAM Role
cognitoAdminIAMRole:
   Type: AWS::IAM::Role
   Properties:
      AssumeRolePolicyDocument:
         Version: "2012-10-17"
         Statement:
            - Effect: "Allow"
              Principal:
                 Federated:
                    - "cognito-identity.amazonaws.com"
              Action:
                 - "sts:AssumeRoleWithWebIdentity"
      Description: "This is the IAM Role the admin group users assume"
      Policies:
         - PolicyName: "youtube-bookstore-admin-group-policy"
           PolicyDocument:
              Version: "2012-10-17"
              Statement:
                 - Effect: "Allow"
                   Resource:
                      - !GetAtt booksTable.Arn
                      - !GetAtt orderTable.Arn
                   Action:
                      - "dynamodb:*"
      RoleName: "youtube-bookstore-admin-role"

# Cognito User Pool Customer Group
cognitoCustomerGroup:
   Type: AWS::Cognito::UserPoolGroup
   Properties:
      Description: "Customers belong to this group"
      GroupName: "customer"
      Precedence: 1
      RoleArn: !GetAtt cognitoUserIAMRole.Arn
      UserPoolId: !Ref cognitoUserPool

# Cognito User IAM Role
cognitoUserIAMRole:
   Type: AWS::IAM::Role
   Properties:
      AssumeRolePolicyDocument:
         Version: "2012-10-17"
         Statement:
            - Effect: "Allow"
              Principal:
                 Federated:
                    - "cognito-identity.amazonaws.com"
              Action:
                 - "sts:AssumeRoleWithWebIdentity"
      Description: "This is the IAM Role the customer group users assume"
      Policies:
         - PolicyName: "youtube-bookstore-customer-group-policy"
           PolicyDocument:
              Version: "2012-10-17"
              Statement:
                 - Effect: "Allow"
                   Resource:
                      - !GetAtt orderTable.Arn
                   Action:
                      - "dynamodb:*"
                 - Effect: "Allow"
                   Resource:
                      - !GetAtt booksTable.Arn
                   Action:
                      - "dynamodb:GetItem"
                      - "dynamodb:Query"
                      - "dynamodb:BatchGetItems"
      RoleName: "youtube-bookstore-customer-role"
raoashish10 commented 1 year ago

Check #596

R11baka commented 11 months ago

@JonnyOrtiz-source you don't need custom property in your yaml file. Example of my config without any custom: sections

appSync:
  name: superProject-${self:provider.stage}
  schema: 'schema.graphql'
  xrayEnabled: true
  authentication:
    type: 'AMAZON_COGNITO_USER_POOLS'
    config:
      userPoolId: 'us-west-1_Vmhdedtd'
    additionalAuthentications:
      - type: 'API_KEY'
  apiKeys:
    - name: apiKey
      description: dev API key
      expiresAfter: 1M