Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

amazon web services - How to deploy a graphql api built with express to AWS serverless?

I have been trying to deploy a backend api service made with graphql api and express to Amazon web services. This is my folder structure

Graphql-api
       -src
           -index.js
       -serverless.yml
       -index.js(this only contains an import statement of the src folder)

The serverless.yml looks like this

service: graphql-api

provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221

functions:
  api:
    handler: src/index.handler
    events:
      - http:
          path: graphql
          method: ANY
          cors: true
            

And I have exported this handler in my src/index.js file

`const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');

const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);`

But when I run serverless deploy and get the endpoint url which is: https://nir4749aal.execute-api.us-east-1.amazonaws.com/dev/graphql I get a message saying internal server error. I can't figure out what I am doing wrong. This is my first time trying to deploy to AWS. Any help or suggestion would help thanks in advance.

-----UPDATE-------- This are the logs from lambda

{
    "errorType": "Runtime.UserCodeSyntaxError",
    "errorMessage": "SyntaxError: Cannot use import statement outside a module",
    "stack": [
        "Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module",
        "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:1015:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)",
        "    at Module.load (internal/modules/cjs/loader.js:879:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It will probably be easier to debug if you check your AWS Lambda logs. Where is your app folder?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...