@@ -10,7 +10,7 @@ let server = null;
10
10
11
11
app . post ( '/2015-03-31/functions/function/invocations' , async ( req , res ) => {
12
12
try {
13
- const body = req . body ? JSON . parse ( req . body ) : req ;
13
+ const body = req . body ? JSON . parse ( req . body ) : ExpressToAWSAPIGatewayProxyEventV2 ( req ) ;
14
14
handler ( body , { } ) . then ( result => {
15
15
res . send ( result ) ;
16
16
} ) . catch ( error => console . error ( error ) ) ;
@@ -20,12 +20,12 @@ app.post('/2015-03-31/functions/function/invocations', async (req, res) => {
20
20
} )
21
21
22
22
app . all ( '/api' , async ( req , res ) => {
23
- handler ( req , { } ) . then ( result => {
23
+ handler ( ExpressToAWSAPIGatewayProxyEventV2 ( req ) , { } ) . then ( result => {
24
24
res . send ( result ) ;
25
25
} ) . catch ( error => console . error ( error ) ) ;
26
26
} ) ;
27
27
app . all ( '/__health' , async ( req , res ) => {
28
- handler ( req , { } ) . then ( result => {
28
+ handler ( ExpressToAWSAPIGatewayProxyEventV2 ( req ) , { } ) . then ( result => {
29
29
res . send ( result ) ;
30
30
} ) . catch ( error => console . error ( error ) ) ;
31
31
} ) ;
@@ -39,8 +39,8 @@ server = app.listen(port, () => {
39
39
if ( process . argv [ 2 ] ) {
40
40
const testFilename = process . argv [ 3 ] || 'service-collection.postman_collection.json'
41
41
42
- console . log ( 'Running Newman tests' ) ;
43
42
if ( ! existsSync ( `./${ testFilename } ` ) ) {
43
+ console . log ( 'Running Newman tests' ) ;
44
44
console . error ( `Error: test collection not found
45
45
./${ testFilename }
46
46
@@ -63,4 +63,86 @@ server = app.listen(port, () => {
63
63
process . exit ( ) ;
64
64
} )
65
65
}
66
- } )
66
+ } )
67
+
68
+ function ExpressToAWSAPIGatewayProxyEventV2 ( request ) {
69
+ return {
70
+ "resource" : request . path ,
71
+ "path" : request . path ,
72
+ "httpMethod" : request . method ,
73
+ "headers" : {
74
+ "header1" : "value1" ,
75
+ "header2" : "value2"
76
+ } ,
77
+ "multiValueHeaders" : {
78
+ "header1" : [
79
+ "value1"
80
+ ] ,
81
+ "header2" : [
82
+ "value1" ,
83
+ "value2"
84
+ ]
85
+ } ,
86
+ "queryStringParameters" : {
87
+ "parameter1" : "value1" ,
88
+ "parameter2" : "value"
89
+ } ,
90
+ "multiValueQueryStringParameters" : {
91
+ "parameter1" : [
92
+ "value1" ,
93
+ "value2"
94
+ ] ,
95
+ "parameter2" : [
96
+ "value"
97
+ ]
98
+ } ,
99
+ "requestContext" : {
100
+ "accountId" : "123456789012" ,
101
+ "apiId" : "id" ,
102
+ "authorizer" : {
103
+ "claims" : null ,
104
+ "scopes" : null
105
+ } ,
106
+ "domainName" : "id.execute-api.us-east-1.amazonaws.com" ,
107
+ "domainPrefix" : "id" ,
108
+ "extendedRequestId" : "request-id" ,
109
+ "httpMethod" : "GET" ,
110
+ "identity" : {
111
+ "accessKey" : null ,
112
+ "accountId" : null ,
113
+ "caller" : null ,
114
+ "cognitoAuthenticationProvider" : null ,
115
+ "cognitoAuthenticationType" : null ,
116
+ "cognitoIdentityId" : null ,
117
+ "cognitoIdentityPoolId" : null ,
118
+ "principalOrgId" : null ,
119
+ "sourceIp" : "IP" ,
120
+ "user" : null ,
121
+ "userAgent" : "user-agent" ,
122
+ "userArn" : null ,
123
+ "clientCert" : {
124
+ "clientCertPem" : "CERT_CONTENT" ,
125
+ "subjectDN" : "www.example.com" ,
126
+ "issuerDN" : "Example issuer" ,
127
+ "serialNumber" : "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1" ,
128
+ "validity" : {
129
+ "notBefore" : "May 28 12:30:02 2019 GMT" ,
130
+ "notAfter" : "Aug 5 09:36:04 2021 GMT"
131
+ }
132
+ }
133
+ } ,
134
+ "path" : "/my/path" ,
135
+ "protocol" : "HTTP/1.1" ,
136
+ "requestId" : "id=" ,
137
+ "requestTime" : "04/Mar/2020:19:15:17 +0000" ,
138
+ "requestTimeEpoch" : 1583349317135 ,
139
+ "resourceId" : null ,
140
+ "resourcePath" : "/my/path" ,
141
+ "stage" : "$default"
142
+ } ,
143
+ "pathParameters" : null ,
144
+ "stageVariables" : null ,
145
+ "body" : "Hello from Lambda!" ,
146
+ "isBase64Encoded" : false
147
+ }
148
+ }
0 commit comments