Skip to content

fix(#18): expose aws context #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Application, Context, MemoryRequest, MemoryResponse } from '@curveball/core';
import { APIGatewayProxyHandler, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { Context as AwsContext, APIGatewayProxyHandler, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import qs from 'querystring';
import { convertBody, convertHeaders } from './util';

export default function lambdaHandler(app: Application): APIGatewayProxyHandler {

return async (awsEvent: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
return async (awsEvent:APIGatewayProxyEvent, awsContext: AwsContext): Promise<APIGatewayProxyResult> => {

const request = new MemoryRequest(
awsEvent.httpMethod,
Expand All @@ -14,7 +14,8 @@ export default function lambdaHandler(app: Application): APIGatewayProxyHandler
awsEvent.isBase64Encoded ? Buffer.from(awsEvent.body ?? '', 'base64') : awsEvent.body,
);
const response = new MemoryResponse();
const context = new Context(request, response);
const context = new Context(request, response) ;
context.aws = { context: awsContext, event: awsEvent };

await app.handle(context);

Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { Context as AwsContext, APIGatewayProxyEvent } from 'aws-lambda'

export type KeyMultiValue = {
[name: string]: string[]
};

declare module "@curveball/core" {
interface Context {
aws?: { context: AwsContext, event: APIGatewayProxyEvent }
}
}