简体   繁体   English

AWS-LAMBDA:没有这样的文件或目录,打开'./src/graphql/schema.graphql'

[英]AWS-LAMBDA: no such file or directory, open './src/graphql/schema.graphql'

I am practicing Graphql and AWS.我正在练习 Graphql 和 AWS。 I used simple serverless framework also create simple Graphql schema.我使用简单的无服务器框架也创建了简单的 Graphql 架构。 I deployed the schema(seems like this graphql.schema file does not deploy), resolvers to AWS.我部署了架构(好像这个graphql.schema文件没有部署),解析器到 AWS。 It successfully create a DynamoDB table and lambda.它成功创建了 DynamoDB 表和 lambda。 I can able make POST/GET request via Graphql Playground by using serverless-offline.我可以使用 serverless-offline 通过 Graphql Playground 发出 POST/GET 请求。 But the issue is the the api end-point does not work.但问题是 api 端点不起作用。 It's show me internal server error .它向我显示internal server error I was investigating the issue.我正在调查这个问题。 From cloud watch I found the local schema which I created the Lambda function did find the graphql.schema .从 cloud watch 我发现了我创建的本地模式 Lambda function 确实找到了graphql.schema This is the error I am getting "ENOENT: no such file or directory, open './src/graphql/schema.graphql'".这是我得到的错误"ENOENT: no such file or directory, open './src/graphql/schema.graphql'". This is the lambda error Image这是 lambda 错误图像

This is my lambda function这是我的 lambda function

 import { ApolloServer } from 'apollo-server-lambda'; import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core'; import runWarm from '../utils/run-warm'; import fs from 'fs'; const schema = fs.readFileSync('./src/graphql/schema.graphql', 'utf8'); // This is local my schema import resolvers from '../resolvers'; const server = new ApolloServer({ typeDefs: schema, resolvers, introspection: true, plugins: [ApolloServerPluginLandingPageGraphQLPlayground()], }); export default runWarm( server.createHandler({ expressGetMiddlewareOptions: { cors: { origin: '*', credentials: true, allowedHeaders: ['Content-Type', 'Origin', 'Accept'], optionsSuccessStatus: 200, }, }, }) );

This is my serverless YAML file这是我的无服务器 YAML 文件

 service: serverless-aws-graphql package: individually: true provider: name: aws profile: ${env:profile} runtime: nodejs14.x stage: ${env:stage} region: eu-north-1 timeout: 30 apiName: ${self:service.name}-${self:provider.stage} environment: ITEM_TABLE: ${self:service}-items-${self:provider.stage} iamRoleStatements: - Effect: Allow Action: - dynamodb:Query - dynamodb:Scan - dynamodb:GetItem - dynamodb:PutItem - dynamodb:UpdateItem - dynamodb:DeleteItem Resource: 'arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.ITEM_TABLE}' apiGateway: shouldStartNameWithService: true custom: webpack: webpackConfig: ./webpack.config.js includeModules: true packager: 'npm' # Packager that will be used to package your external modules warmup: enabled: true events: - schedule: rate(5 minutes) prewarm: true concurrency: 1 prune: automatic: true number: 5 functions: graphql: handler: src/handlers/graphql.default events: - http: path: ${env:api_prefix}/graphql method: any cors: true resources: Resources: ItemsTable: Type: 'AWS::DynamoDB::Table' Properties: AttributeDefinitions: - AttributeName: PK AttributeType: S - AttributeName: SK AttributeType: S - AttributeName: GSI1PK AttributeType: S - AttributeName: GSI1SK AttributeType: S KeySchema: - AttributeName: PK KeyType: HASH - AttributeName: SK KeyType: RANGE ProvisionedThroughput: ReadCapacityUnits: 1 WriteCapacityUnits: 1 GlobalSecondaryIndexes: - IndexName: GSI1 KeySchema: - AttributeName: GSI1PK KeyType: HASH - AttributeName: GSI1SK KeyType: RANGE Projection: ProjectionType: ALL ProvisionedThroughput: ReadCapacityUnits: 1 WriteCapacityUnits: 1 TableName: ${self:provider.environment.ITEM_TABLE} plugins: - serverless-webpack - serverless-offline - serverless-plugin-warmup - serverless-dotenv-plugin - serverless-prune-plugin

As you observed, the ./src/graphql/schema.graphql isn't being packaged to the final artifact Serverless builds and deploys.正如您所观察到的,. ./src/graphql/schema.graphql没有被打包到最终的工件无服务器构建和部署中。

You can add it by specifying the package property to your function:您可以通过将package属性指定到 function 来添加它:

graphql:
  handler: src/handlers/graphql.default
  events:
    - http:
        path: ${env:api_prefix}/graphql
        method: any
        cors: true
  package:
    include:
      - src/graphql/schema.graphql

Source: https://www.serverless.com/framework/docs/providers/aws/guide/packaging#patterns资料来源: https://www.serverless.com/framework/docs/providers/aws/guide/packaging#patterns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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