curveball / aws-lambda

Run curveball applications on AWS Lambda
MIT License
7 stars 2 forks source link

AWS Context not exposed #18

Open moeriki opened 4 years ago

moeriki commented 4 years ago

The default AWS handler has two arguments: event, and context.

It seems like context is not used in curveball, which is fine. But it would be convenient to have it available on the ctx.request.

Right now if I want to access the AWS context I have to do this before forwarding the event to Curveball.

export function handle(event: any, context: Context): Promise<any> {
  context.callbackWaitsForEmptyEventLoop = false;
  return handler(app)(event);
}

Additionally there are internal types for AwsRequest and AwsResponse that are not exposed. I had to type them as any in the code above.

Would you accept PR to:

evert commented 4 years ago

Sounds like a great idea.

I think I would like the property to live on ctx, not ctx.request.

Since the last curveball version Context is now an interface, so it's possible to also get full typing for it via declaration merging.

So maybe ctx.aws.context and ctx.aws.event ?

moeriki commented 4 years ago

Oh yeah ctx.aws makes total sense.

I made a WIP PR to get the idea across. Is that what you had in mind?

I set the context for now to any. I was wondering if you know about @types/aws-lambda? It's got types for the AWS context, event (request), response, and context. At the moment these are typed within this package. Is there a reason for not using it? And would you mind using aws-lambda types instead.

evert commented 4 years ago

I'm very down with using @types/aws-lamba! I recently worked on https://github.com/curveball/azure-function/ , and did the same there.

Makes total sense.

moeriki commented 4 years ago

Great. I will make the PR for that first then. So I can immediately use the existing aws Context interface.