Can't get the API Gateway event object
See original GitHub issueI use aws-serverless-express/middleware but can’t get the API Gateway event object. Here is my code.
...
import awsServerlessExpress from 'aws-serverless-express';
import awsServerlessExpressMiddleware from 'aws-serverless-express/middleware';
...
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
api.use(awsServerlessExpressMiddleware.eventContext());
app.use('/', api);
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
When i use access req.apiGateway.event, error has occurred like below.
TypeError: Cannot read property 'event' of undefined
Am i missing something? or is this bug?
Issue Analytics
- State:
- Created 5 years ago
- Comments:15
Top Results From Across the Web
Using AWS Lambda with Amazon API Gateway
This section explains general information on how to choose an API type, add an endpoint to your Lambda function, and information on events,...
Read more >Can't access 'event' properties when calling it in Lambda ...
So I believe I solved the issue. I simply un-ticked the 'use lambda proxy integration' box when setting up the post method in...
Read more >How to create a Request object for your Lambda event from ...
In your AWS Console open up your API Gateway and find the method you want to provide headers. Locate the Integration Request box...
Read more >Fix the Most Common API Gateway Request Errors - Dashbird
Again, a retry doesn't help here. If you use end-user authentication with AWS Cognito, every request will get a temporary role related to...
Read more >API (REST) - Fetching data - JavaScript - AWS Amplify Docs
Using the GET API REST in Amplify - JavaScript - AWS Amplify Docs. ... access your query parameters & body within your Lambda...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In case any other lost souls who are encountering
Missing x-apigateway-event or x-apigateway-context header(s)
when doing local testing (e.g. from Postman) find their way here… You have to set both of thex-apigateway-event
andx-apigateway-context
headers in Postman. The important thing is their values have to beSo for instance, if the header key is:
x-apigateway-event
Then the value should be%7B%22data%22%3A%22Sand%22%2C%22public_key%22%3A%22key%22%7D
Note, there are no quotes around the encoded and stringified value!
You have to set both
x-apigateway-event
andx-apigateway-context
headers because if you peek in yournode_modules/aws-serverless-express/src/middleware.js
file you’ll see it has the following lines:aws-serverless-express
library is being deprecated and moving to vendia. Here is how it should be done using vendia libraryGuide: https://github.com/vendia/serverless-express#accessing-the-event-and-context-objects
Source: https://www.npmjs.com/package/aws-serverless-express#:~:text=AWS Serverless Express library is moving to Vendia and will be rebranded to serverless-express. Similarly%2C the aws-serverless-express NPM package will be deprecated in favor of a new serverless-express package