sst icon indicating copy to clipboard operation
sst copied to clipboard

Bug in minimal typescript starter: `event.requestContext` is not defined

Open cprice404 opened this issue 3 years ago • 1 comments

I did the following:

  • npx create-sst@latest my-sst-app
  • chose 'minimal'
  • chose 'minimal/typescript-starter'
  • cd my-sst-app
  • npm install
  • npx sst start
  • Opened up the SST console and invoked the lambda

The above steps resulted in the following error:

TypeError: Cannot read properties of undefined (reading 'time')

The offending line of code is this one:

body: `Hello, World! Your request was received at ${event.requestContext.time}.`,

because event.requestContext is undefined. In fact, event is an empty Object with no properties.

If I change the function signature from this:

export const handler: APIGatewayProxyHandlerV2 = async (event) => {

to this:

export const handler: APIGatewayProxyHandlerV2 = async (event, context) => {

Then I can see some request context information populated on the context object. It still doesn't have a property called time, though.

cprice404 avatar Nov 30 '22 01:11 cprice404

Technically that example is meant to just respond to an API request, as in you hit the API endpoint it generates. We should probably take it out since you can directly invoke the function like you did.

jayair avatar Dec 01 '22 01:12 jayair