question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

integration: lambda gives "Unable to determine event source based on event."

See original GitHub issue

Hi all,

When deploying using serverless with serverless-api-gateway-caching like so:

functions:
  graphql:
    handler: src/handler.graphqlHandler
    events:
    - http:
        path: graphql
        method: post
        cors: true
        integration: lambda
        caching:
          enabled: true
          cacheKeyParameters:
            - name: integration.request.header.bodyValue
              mappedFrom: method.request.body

The event is structured like this:

{
  body: {
    ...gql...
  },
  method: 'POST',
  principalId: '',
  stage: 'dev',
  cognitoPoolClaims: { sub: '' },
  enhancedAuthContext: {},
  headers: {
    Accept: '*/*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-GB,en;q=0.5',
    'cache-control': 'no-cache',
    'CloudFront-Forwarded-Proto': 'https',
    'CloudFront-Is-Desktop-Viewer': 'true',
    'CloudFront-Is-Mobile-Viewer': 'false',
    'CloudFront-Is-SmartTV-Viewer': 'false',
    'CloudFront-Is-Tablet-Viewer': 'false',
    'CloudFront-Viewer-Country': 'GB',
    'content-type': 'application/json',
    dnt: '1',
    Host: '...host url...',
    origin: 'https://...origin url...',
    pragma: 'no-cache',
    Referer: 'https://...referrer url...',
    'sec-gpc': '1',
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
    Via: '2.0 xxxxxx.cloudfront.net (CloudFront)',
    'X-Amz-Cf-Id': 'xxxxxx',
    'X-Amzn-Trace-Id': 'Root=xxxxxx',
    'X-Forwarded-For': '...some ips...',
    'X-Forwarded-Port': '443',
    'X-Forwarded-Proto': 'https'
  },
  query: {},
  path: {},
  identity: {
    cognitoIdentityPoolId: '',
    accountId: '',
    cognitoIdentityId: '',
    caller: '',
    sourceIp: '...ip...',
    principalOrgId: '',
    accessKey: '',
    cognitoAuthenticationType: '',
    cognitoAuthenticationProvider: '',
    userArn: '',
    userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
    user: ''
  },
  stageVariables: {},
  requestPath: '/graphql'
}

It seems you cannot enable method.request.body cacheKeyParameters without integration: lambda which seems to mess with the event.

Should this be an event type we are able to handle or am I missing a setting to turn it in to an event that can be handled?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
sebastien-abbalcommented, Feb 28, 2022

I had this problem with serverless-plugin-warmup, and i need to set my payload event like this:

{
  "body": null,
  "httpMethod": "GET",
  "path": "/my-path",
  "requestContext": {}
}

–> Now, it’s all working well 😃

1reaction
electeriouscommented, Jan 16, 2022

Getting the same error when using @vendia/serverless-express via apollo-server-lambda on Vercel.

[POST] /api
19:28:08:34
2022-01-09T18:28:10.719Z	2014d7ba-295d-4344-a94a-007608d4788b	ERROR	Invoke Error 	{"errorType":"Error","errorMessage":"Unable to determine event source based on event.","stack":["Error: Unable to determine event source based on event.","    at getEventSourceNameBasedOnEvent (/var/task/node_modules/@vendia/serverless-express/src/event-sources/utils.js:88:9)","    at proxy (/var/task/node_modules/@vendia/serverless-express/src/configure.js:38:51)","    at handler (/var/task/node_modules/@vendia/serverless-express/src/configure.js:99:12)","    at Object.handler (/var/task/node_modules/apollo-server-lambda/dist/ApolloServer.js:51:27)"]}
Read more comments on GitHub >

github_iconTop Results From Across the Web

apollo-server-lambda: Unable to determine event source ...
Within serverless-express, in src/event-sources/utils.js, there is a function called getEventSourceNameBasedOnEvent(), which is throwing the ...
Read more >
Unable to determine event source based on event. (apollo ...
I have this issue after updating to apollo-server-lambda@3^ “Error: Unable to determine event source based on event.” This code used to work ...
Read more >
Using Lambda with Amazon SQS - AWS Documentation
Create an SQS queue to serve as an event source for your Lambda function. Then configure the queue to allow time for your...
Read more >
REST API (API Gateway v1) - Serverless Framework
To create HTTP endpoints as Event sources for your AWS Lambda Functions, ... Use http for integrating with an HTTP back end, http-proxy...
Read more >
Netlify, apollo-server-lambda, and Webpack walked into a bar…
requestContext and then we are clear to run graphqlHandler(event, context) . Without that fix you will see the error “Unable to determine event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found