@cumulusds/aws-apig-bypass 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/create-api-gateway-event.d.ts +54 -0
- package/lib/create-api-gateway-event.js +38 -54
- package/lib/create-api-gateway-event.js.flow +43 -53
- package/lib/create-client.d.ts +19 -0
- package/lib/create-client.js +10 -14
- package/lib/create-client.js.flow +15 -14
- package/lib/create-lambda-client.d.ts +39 -0
- package/lib/create-lambda-client.js +32 -30
- package/lib/create-lambda-client.js.flow +18 -45
- package/lib/index.d.ts +3 -0
- package/lib/index.js +9 -19
- package/lib/index.js.flow +8 -3
- package/lib/json-stringify.d.ts +7 -0
- package/lib/json-stringify.js +7 -11
- package/lib/json-stringify.js.flow +7 -10
- package/lib/lambda-invoke.d.ts +7 -0
- package/lib/lambda-invoke.js +2 -1
- package/lib/lambda-invoke.js.flow +8 -2
- package/lib/parse-payload.d.ts +9 -0
- package/lib/parse-payload.js +13 -17
- package/lib/parse-payload.js.flow +17 -17
- package/lib/response.d.ts +10 -0
- package/lib/response.js +2 -1
- package/lib/response.js.flow +12 -9
- package/package.json +28 -34
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Bypass the API Gateway by directly invoking the Lambda handler that backs an endpoint.
|
|
4
4
|
|
|
5
|
-
We often build externally accessible REST endpoints using API Gateway and Lambda. Sometimes we have an endpoint with both internal and external (outside of AWS) clients. The API Gateway provides some value to external clients, since it helps authorize and rate-limit requests. However, it is a
|
|
5
|
+
We often build externally accessible REST endpoints using API Gateway and Lambda. Sometimes we have an endpoint with both internal and external (outside of AWS) clients. The API Gateway provides some value to external clients, since it helps authorize and rate-limit requests. However, it is a hindrance to internal clients, where we have other means of rate-limiting. Access control is often more consistent if we rely on IAM policies. The API Gateway adds cost and reduces convenience for internal clients.
|
|
6
6
|
|
|
7
7
|
This library provides an adapter for the Lambda SDK to make it easy to directly invoke the handler.
|
|
8
8
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { APIGatewayEvent } from "aws-lambda";
|
|
2
|
+
export type PathParameters = {
|
|
3
|
+
[name: string]: string;
|
|
4
|
+
} | null;
|
|
5
|
+
export type QueryStringParameters = {
|
|
6
|
+
[name: string]: string;
|
|
7
|
+
} | null;
|
|
8
|
+
declare const defaultRequestContext: {
|
|
9
|
+
accountId: string;
|
|
10
|
+
apiId: string;
|
|
11
|
+
httpMethod: string;
|
|
12
|
+
identity: {
|
|
13
|
+
accessKey: null;
|
|
14
|
+
accountId: null;
|
|
15
|
+
apiKey: null;
|
|
16
|
+
caller: null;
|
|
17
|
+
cognitoAuthenticationProvider: null;
|
|
18
|
+
cognitoAuthenticationType: null;
|
|
19
|
+
cognitoIdentityId: null;
|
|
20
|
+
cognitoIdentityPoolId: null;
|
|
21
|
+
sourceIp: string;
|
|
22
|
+
user: null;
|
|
23
|
+
userAgent: null;
|
|
24
|
+
userArn: null;
|
|
25
|
+
};
|
|
26
|
+
stage: string;
|
|
27
|
+
requestId: string;
|
|
28
|
+
resourceId: string;
|
|
29
|
+
resourcePath: string;
|
|
30
|
+
};
|
|
31
|
+
export type CreateAPIGatewayEventOptions = {
|
|
32
|
+
body?: string | null;
|
|
33
|
+
headers?: {
|
|
34
|
+
[name: string]: string;
|
|
35
|
+
};
|
|
36
|
+
multiValueHeaders?: {
|
|
37
|
+
[name: string]: string[];
|
|
38
|
+
};
|
|
39
|
+
httpMethod?: string;
|
|
40
|
+
isBase64Encoded?: boolean;
|
|
41
|
+
path?: string;
|
|
42
|
+
pathParameters?: PathParameters;
|
|
43
|
+
queryStringParameters?: QueryStringParameters;
|
|
44
|
+
multiValueQueryStringParameters?: {
|
|
45
|
+
[name: string]: string[];
|
|
46
|
+
};
|
|
47
|
+
stageVariables?: {
|
|
48
|
+
[name: string]: string;
|
|
49
|
+
};
|
|
50
|
+
requestContext?: typeof defaultRequestContext;
|
|
51
|
+
resource?: string;
|
|
52
|
+
};
|
|
53
|
+
export default function createAPIGatewayEvent({ body, headers, multiValueHeaders, httpMethod, isBase64Encoded, pathParameters, path, queryStringParameters, multiValueQueryStringParameters, stageVariables, requestContext, resource, }?: CreateAPIGatewayEventOptions): APIGatewayEvent;
|
|
54
|
+
export {};
|
|
@@ -1,58 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.default = createAPIGatewayEvent;
|
|
7
4
|
const defaultRequestContext = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
accountId: "",
|
|
6
|
+
apiId: "",
|
|
7
|
+
httpMethod: "",
|
|
8
|
+
identity: {
|
|
9
|
+
accessKey: null,
|
|
10
|
+
accountId: null,
|
|
11
|
+
apiKey: null,
|
|
12
|
+
caller: null,
|
|
13
|
+
cognitoAuthenticationProvider: null,
|
|
14
|
+
cognitoAuthenticationType: null,
|
|
15
|
+
cognitoIdentityId: null,
|
|
16
|
+
cognitoIdentityPoolId: null,
|
|
17
|
+
sourceIp: "",
|
|
18
|
+
user: null,
|
|
19
|
+
userAgent: null,
|
|
20
|
+
userArn: null,
|
|
21
|
+
},
|
|
22
|
+
stage: "",
|
|
23
|
+
requestId: "",
|
|
24
|
+
resourceId: "",
|
|
25
|
+
resourcePath: "",
|
|
29
26
|
};
|
|
30
|
-
function createAPIGatewayEvent({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers,
|
|
47
|
-
multiValueHeaders,
|
|
48
|
-
httpMethod,
|
|
49
|
-
isBase64Encoded,
|
|
50
|
-
path,
|
|
51
|
-
pathParameters,
|
|
52
|
-
queryStringParameters,
|
|
53
|
-
multiValueQueryStringParameters,
|
|
54
|
-
stageVariables,
|
|
55
|
-
requestContext,
|
|
56
|
-
resource
|
|
57
|
-
};
|
|
58
|
-
}
|
|
27
|
+
function createAPIGatewayEvent({ body = null, headers = {}, multiValueHeaders = {}, httpMethod = "", isBase64Encoded = false, pathParameters = null, path = "", queryStringParameters = null, multiValueQueryStringParameters = {}, stageVariables = {}, requestContext = defaultRequestContext, resource = "", } = {}) {
|
|
28
|
+
return {
|
|
29
|
+
body,
|
|
30
|
+
headers,
|
|
31
|
+
multiValueHeaders,
|
|
32
|
+
httpMethod,
|
|
33
|
+
isBase64Encoded,
|
|
34
|
+
path,
|
|
35
|
+
pathParameters,
|
|
36
|
+
queryStringParameters,
|
|
37
|
+
multiValueQueryStringParameters,
|
|
38
|
+
stageVariables,
|
|
39
|
+
requestContext,
|
|
40
|
+
resource,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for create-api-gateway-event
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
|
-
import type { APIGatewayEvent } from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import type { APIGatewayEvent } from "aws-lambda";
|
|
9
|
+
export type PathParameters = {
|
|
10
|
+
[name: string]: string,
|
|
11
|
+
} | null;
|
|
12
|
+
export type QueryStringParameters = {
|
|
13
|
+
[name: string]: string,
|
|
14
|
+
} | null;
|
|
15
|
+
declare var defaultRequestContext: {
|
|
16
|
+
accountId: string,
|
|
17
|
+
apiId: string,
|
|
18
|
+
httpMethod: string,
|
|
12
19
|
identity: {
|
|
13
20
|
accessKey: null,
|
|
14
21
|
accountId: null,
|
|
@@ -18,58 +25,41 @@ const defaultRequestContext = {
|
|
|
18
25
|
cognitoAuthenticationType: null,
|
|
19
26
|
cognitoIdentityId: null,
|
|
20
27
|
cognitoIdentityPoolId: null,
|
|
21
|
-
sourceIp:
|
|
28
|
+
sourceIp: string,
|
|
22
29
|
user: null,
|
|
23
30
|
userAgent: null,
|
|
24
|
-
userArn: null
|
|
31
|
+
userArn: null,
|
|
32
|
+
...
|
|
25
33
|
},
|
|
26
|
-
stage:
|
|
27
|
-
requestId:
|
|
28
|
-
resourceId:
|
|
29
|
-
resourcePath:
|
|
34
|
+
stage: string,
|
|
35
|
+
requestId: string,
|
|
36
|
+
resourceId: string,
|
|
37
|
+
resourcePath: string,
|
|
38
|
+
...
|
|
30
39
|
};
|
|
31
|
-
|
|
32
40
|
export type CreateAPIGatewayEventOptions = {
|
|
33
|
-
body?: string,
|
|
34
|
-
headers?: {
|
|
35
|
-
|
|
41
|
+
body?: string | null,
|
|
42
|
+
headers?: {
|
|
43
|
+
[name: string]: string,
|
|
44
|
+
},
|
|
45
|
+
multiValueHeaders?: {
|
|
46
|
+
[name: string]: string[],
|
|
47
|
+
},
|
|
36
48
|
httpMethod?: string,
|
|
37
49
|
isBase64Encoded?: boolean,
|
|
38
50
|
path?: string,
|
|
39
51
|
pathParameters?: PathParameters,
|
|
40
52
|
queryStringParameters?: QueryStringParameters,
|
|
41
|
-
multiValueQueryStringParameters?: {
|
|
42
|
-
|
|
53
|
+
multiValueQueryStringParameters?: {
|
|
54
|
+
[name: string]: string[],
|
|
55
|
+
},
|
|
56
|
+
stageVariables?: {
|
|
57
|
+
[name: string]: string,
|
|
58
|
+
},
|
|
43
59
|
requestContext?: typeof defaultRequestContext,
|
|
44
|
-
resource?: string
|
|
60
|
+
resource?: string,
|
|
61
|
+
...
|
|
45
62
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
headers = {},
|
|
50
|
-
multiValueHeaders = {},
|
|
51
|
-
httpMethod = "",
|
|
52
|
-
isBase64Encoded = false,
|
|
53
|
-
pathParameters = null,
|
|
54
|
-
path = "",
|
|
55
|
-
queryStringParameters = null,
|
|
56
|
-
multiValueQueryStringParameters = null,
|
|
57
|
-
stageVariables = null,
|
|
58
|
-
requestContext = defaultRequestContext,
|
|
59
|
-
resource = ""
|
|
60
|
-
}: CreateAPIGatewayEventOptions = {}): APIGatewayEvent<string> {
|
|
61
|
-
return {
|
|
62
|
-
body,
|
|
63
|
-
headers,
|
|
64
|
-
multiValueHeaders,
|
|
65
|
-
httpMethod,
|
|
66
|
-
isBase64Encoded,
|
|
67
|
-
path,
|
|
68
|
-
pathParameters,
|
|
69
|
-
queryStringParameters,
|
|
70
|
-
multiValueQueryStringParameters,
|
|
71
|
-
stageVariables,
|
|
72
|
-
requestContext,
|
|
73
|
-
resource
|
|
74
|
-
};
|
|
75
|
-
}
|
|
63
|
+
declare export default function createAPIGatewayEvent(
|
|
64
|
+
x?: CreateAPIGatewayEventOptions
|
|
65
|
+
): APIGatewayEvent;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { APIGatewayEvent } from "aws-lambda";
|
|
2
|
+
import type { Response } from "./response";
|
|
3
|
+
import type { LambdaInvoke } from "./lambda-invoke";
|
|
4
|
+
/**
|
|
5
|
+
* Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
|
|
6
|
+
*/
|
|
7
|
+
export type APIGatewayHandlerClient<T> = (event: APIGatewayEvent) => Promise<Response<T>>;
|
|
8
|
+
export type CreateClientOptions<T> = {
|
|
9
|
+
Lambda: LambdaInvoke;
|
|
10
|
+
FunctionName: string;
|
|
11
|
+
Validate?: (arg1: T) => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
|
|
15
|
+
*
|
|
16
|
+
* @param options
|
|
17
|
+
* @returns {APIGatewayHandlerClient<T>}
|
|
18
|
+
*/
|
|
19
|
+
export default function createClient<T>(options: CreateClientOptions<T>): APIGatewayHandlerClient<T>;
|
package/lib/create-client.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = createClient;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
/**
|
|
12
|
-
* Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
|
|
13
|
-
*/
|
|
7
|
+
const create_lambda_client_1 = __importDefault(require("./create-lambda-client"));
|
|
8
|
+
const json_stringify_1 = __importDefault(require("./json-stringify"));
|
|
9
|
+
const parse_payload_1 = __importDefault(require("./parse-payload"));
|
|
14
10
|
/**
|
|
15
11
|
* Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
|
|
16
12
|
*
|
|
@@ -18,6 +14,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
14
|
* @returns {APIGatewayHandlerClient<T>}
|
|
19
15
|
*/
|
|
20
16
|
function createClient(options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
17
|
+
const client = (0, create_lambda_client_1.default)(options);
|
|
18
|
+
return async (event) => (0, parse_payload_1.default)(await client((0, json_stringify_1.default)(event)));
|
|
19
|
+
}
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for create-client
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
|
-
import
|
|
4
|
-
import createLambdaClient from "./create-lambda-client";
|
|
8
|
+
import { APIGatewayEvent } from "aws-lambda";
|
|
5
9
|
import type { Response } from "./response";
|
|
6
|
-
import jsonStringify from "./json-stringify";
|
|
7
|
-
import parsePayload from "./parse-payload";
|
|
8
10
|
import type { LambdaInvoke } from "./lambda-invoke";
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Client that directly invokes an API Gateway handler, bypassing the gateway. The client handles packing and unpacking messages for invoking the handler.
|
|
12
14
|
*/
|
|
13
|
-
export type APIGatewayHandlerClient<T> = (
|
|
14
|
-
|
|
15
|
+
export type APIGatewayHandlerClient<T> = (
|
|
16
|
+
event: APIGatewayEvent
|
|
17
|
+
) => Promise<Response<T>>;
|
|
15
18
|
export type CreateClientOptions<T> = {
|
|
16
19
|
Lambda: LambdaInvoke,
|
|
17
20
|
FunctionName: string,
|
|
18
|
-
Validate?: T => void
|
|
21
|
+
Validate?: (arg1: T) => void,
|
|
22
|
+
...
|
|
19
23
|
};
|
|
20
|
-
|
|
21
24
|
/**
|
|
22
25
|
* Create an APIGatewayHandlerClient. The client invokes an API Gateway handler, bypassing the gateway. It adapts the AWS SDK by packing and unpacking messages for invoking the handler.
|
|
23
|
-
*
|
|
24
26
|
* @param options
|
|
25
27
|
* @returns {APIGatewayHandlerClient<T>}
|
|
26
28
|
*/
|
|
27
|
-
export default function createClient<T>(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
29
|
+
declare export default function createClient<T>(
|
|
30
|
+
options: CreateClientOptions<T>
|
|
31
|
+
): APIGatewayHandlerClient<T>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Lambda } from "aws-sdk";
|
|
2
|
+
import type { LambdaInvoke } from "./lambda-invoke";
|
|
3
|
+
type _Blob = Buffer | Uint8Array | Blob | string;
|
|
4
|
+
type LambdaClientType = (event: _Blob) => Promise<string>;
|
|
5
|
+
export type CreateLambdaClientOptions = {
|
|
6
|
+
Lambda: LambdaInvoke;
|
|
7
|
+
FunctionName: string;
|
|
8
|
+
};
|
|
9
|
+
export type Lambda$InvocationResponse = {
|
|
10
|
+
/**
|
|
11
|
+
* The HTTP status code is in the 200 range for a successful request. For the RequestResponse invocation type, this status code is 200. For the Event invocation type, this status code is 202. For the DryRun invocation type, the status code is 204.
|
|
12
|
+
*/
|
|
13
|
+
StatusCode?: number;
|
|
14
|
+
/**
|
|
15
|
+
* If present, indicates that an error occurred during function execution. Details about the error are included in the response payload.
|
|
16
|
+
*/
|
|
17
|
+
FunctionError?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The last 4 KB of the execution log, which is base64 encoded.
|
|
20
|
+
*/
|
|
21
|
+
LogResult?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The response from the function, or an error object.
|
|
24
|
+
*/
|
|
25
|
+
Payload?: Buffer | Uint8Array | Blob | string;
|
|
26
|
+
/**
|
|
27
|
+
* The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.
|
|
28
|
+
*/
|
|
29
|
+
ExecutedVersion?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare class LambdaInvokeError extends Error {
|
|
32
|
+
code: string;
|
|
33
|
+
constructor(response: Lambda.InvocationResponse);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* AWS Lambda SDK adapter for createClient.
|
|
37
|
+
*/
|
|
38
|
+
export default function createLambdaClient({ Lambda: LambdaShadow, FunctionName, }: CreateLambdaClientOptions): LambdaClientType;
|
|
39
|
+
export {};
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = createLambdaClient;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.LambdaInvokeError = void 0;
|
|
4
|
+
exports.default = createLambdaClient;
|
|
8
5
|
class LambdaInvokeError extends Error {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
code;
|
|
7
|
+
constructor(response) {
|
|
8
|
+
super([
|
|
9
|
+
"Invocation Failed",
|
|
10
|
+
response.ExecutedVersion,
|
|
11
|
+
response.StatusCode,
|
|
12
|
+
response.FunctionError,
|
|
13
|
+
response.Payload,
|
|
14
|
+
response.LogResult != null ? Buffer.from(response.LogResult, "base64").toString("utf-8") : null,
|
|
15
|
+
]
|
|
16
|
+
.filter((x) => x != null)
|
|
17
|
+
.join(": "));
|
|
18
|
+
this.code = response.FunctionError ?? "";
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
|
-
|
|
21
|
+
exports.LambdaInvokeError = LambdaInvokeError;
|
|
16
22
|
/**
|
|
17
23
|
* AWS Lambda SDK adapter for createClient.
|
|
18
24
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return invocationResponse.Payload;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
25
|
+
function createLambdaClient({ Lambda: LambdaShadow, FunctionName, }) {
|
|
26
|
+
return async (Payload) => {
|
|
27
|
+
const invocationResponse = await LambdaShadow.invoke({
|
|
28
|
+
FunctionName,
|
|
29
|
+
Payload,
|
|
30
|
+
}).promise();
|
|
31
|
+
if (invocationResponse.StatusCode !== 200 || invocationResponse.FunctionError != null) {
|
|
32
|
+
throw new LambdaInvokeError(invocationResponse);
|
|
33
|
+
}
|
|
34
|
+
if (typeof invocationResponse.Payload !== "string") {
|
|
35
|
+
throw new Error(`AWS Lambda invocation API returned the wrong payload type '${typeof invocationResponse.Payload}'; expected 'string'`);
|
|
36
|
+
}
|
|
37
|
+
return invocationResponse.Payload;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for create-lambda-client
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
8
|
+
import { Lambda } from "aws-sdk";
|
|
3
9
|
import type { LambdaInvoke } from "./lambda-invoke";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type _Blob = Buffer | Uint8Array | Blob | string;
|
|
7
|
-
type LambdaClientType = (event: _Blob) => Promise<string>;
|
|
8
|
-
|
|
10
|
+
declare type _Blob = Buffer | Uint8Array | Blob | string;
|
|
11
|
+
declare type LambdaClientType = (event: _Blob) => Promise<string>;
|
|
9
12
|
export type CreateLambdaClientOptions = {
|
|
10
13
|
Lambda: LambdaInvoke,
|
|
11
|
-
FunctionName: string
|
|
14
|
+
FunctionName: string,
|
|
15
|
+
...
|
|
12
16
|
};
|
|
13
|
-
|
|
14
17
|
export type Lambda$InvocationResponse = {
|
|
15
18
|
/**
|
|
16
19
|
* The HTTP status code is in the 200 range for a successful request. For the RequestResponse invocation type, this status code is 200. For the Event invocation type, this status code is 202. For the DryRun invocation type, the status code is 204.
|
|
@@ -35,46 +38,16 @@ export type Lambda$InvocationResponse = {
|
|
|
35
38
|
/**
|
|
36
39
|
* The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.
|
|
37
40
|
*/
|
|
38
|
-
ExecutedVersion?: string
|
|
41
|
+
ExecutedVersion?: string,
|
|
42
|
+
...
|
|
39
43
|
};
|
|
40
|
-
|
|
41
|
-
export class LambdaInvokeError extends Error {
|
|
44
|
+
declare export class LambdaInvokeError mixins Error {
|
|
42
45
|
code: string;
|
|
43
|
-
|
|
44
|
-
constructor(response: Lambda$InvocationResponse) {
|
|
45
|
-
super(
|
|
46
|
-
[
|
|
47
|
-
"Invocation Failed",
|
|
48
|
-
response.ExecutedVersion,
|
|
49
|
-
response.StatusCode,
|
|
50
|
-
response.FunctionError,
|
|
51
|
-
response.Payload,
|
|
52
|
-
response.LogResult != null ? Buffer.from(response.LogResult, "base64").toString("utf-8") : null
|
|
53
|
-
]
|
|
54
|
-
.filter(x => x != null)
|
|
55
|
-
.join(": ")
|
|
56
|
-
);
|
|
57
|
-
this.code = response.FunctionError ?? "";
|
|
58
|
-
}
|
|
46
|
+
constructor(response: Lambda.InvocationResponse): this;
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
/**
|
|
62
49
|
* AWS Lambda SDK adapter for createClient.
|
|
63
50
|
*/
|
|
64
|
-
export default function createLambdaClient(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
FunctionName,
|
|
68
|
-
Payload
|
|
69
|
-
}).promise();
|
|
70
|
-
if (invocationResponse.StatusCode !== 200 || invocationResponse.FunctionError != null) {
|
|
71
|
-
throw new LambdaInvokeError(invocationResponse);
|
|
72
|
-
}
|
|
73
|
-
if (typeof invocationResponse.Payload !== "string") {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`AWS Lambda invocation API returned the wrong payload type '${typeof invocationResponse.Payload}'; expected 'string'`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
return invocationResponse.Payload;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
51
|
+
declare export default function createLambdaClient(
|
|
52
|
+
x: CreateLambdaClientOptions
|
|
53
|
+
): LambdaClientType;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "createAPIGatewayEvent", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _createApiGatewayEvent.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _createClient = _interopRequireDefault(require("./create-client"));
|
|
19
|
-
var _createApiGatewayEvent = _interopRequireDefault(require("./create-api-gateway-event"));
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAPIGatewayEvent = exports.createClient = void 0;
|
|
7
|
+
var create_client_1 = require("./create-client");
|
|
8
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return __importDefault(create_client_1).default; } });
|
|
9
|
+
var create_api_gateway_event_1 = require("./create-api-gateway-event");
|
|
10
|
+
Object.defineProperty(exports, "createAPIGatewayEvent", { enumerable: true, get: function () { return __importDefault(create_api_gateway_event_1).default; } });
|
package/lib/index.js.flow
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
|
-
export { default as createClient } from "./create-client";
|
|
8
|
+
declare export { default as createClient } from "./create-client";
|
|
4
9
|
export type { APIGatewayHandlerClient } from "./create-client";
|
|
5
|
-
export { default as createAPIGatewayEvent } from "./create-api-gateway-event";
|
|
10
|
+
declare export { default as createAPIGatewayEvent } from "./create-api-gateway-event";
|
package/lib/json-stringify.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.default = jsonStringify;
|
|
7
4
|
/**
|
|
8
5
|
* Stringify to JSON, returning a string or else throwing an exception because of unserializable input.
|
|
@@ -10,11 +7,10 @@ exports.default = jsonStringify;
|
|
|
10
7
|
* @param value
|
|
11
8
|
* @returns {string}
|
|
12
9
|
*/
|
|
13
|
-
// flowlint-next-line unclear-type:off
|
|
14
10
|
function jsonStringify(value) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
11
|
+
const result = JSON.stringify(value);
|
|
12
|
+
if (result == null) {
|
|
13
|
+
throw new Error("Cannot stringify value");
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for json-stringify
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Stringify to JSON, returning a string or else throwing an exception because of unserializable input.
|
|
5
|
-
*
|
|
6
10
|
* @param value
|
|
7
11
|
* @returns {string}
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
export default function jsonStringify(value: any): string {
|
|
11
|
-
const result = JSON.stringify(value);
|
|
12
|
-
if (result == null) {
|
|
13
|
-
throw new Error("Cannot stringify value");
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
13
|
+
declare export default function jsonStringify(value: mixed): string;
|
package/lib/lambda-invoke.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for lambda-invoke
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
8
|
import type { Lambda } from "aws-sdk";
|
|
4
9
|
|
|
@@ -6,5 +11,6 @@ import type { Lambda } from "aws-sdk";
|
|
|
6
11
|
* This library only needs the invoke method from aws-sdk Lambda client.
|
|
7
12
|
*/
|
|
8
13
|
export type LambdaInvoke = {
|
|
9
|
-
+invoke: $PropertyType<Lambda, "invoke"
|
|
14
|
+
+invoke: $PropertyType<Lambda, "invoke">,
|
|
15
|
+
...
|
|
10
16
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Response } from "./response";
|
|
2
|
+
/**
|
|
3
|
+
* Decode the handler response
|
|
4
|
+
*
|
|
5
|
+
* @param payload
|
|
6
|
+
* @param validate if given, the validate function is called on the parsed response body. The function should throw an exception if the response is invalid.
|
|
7
|
+
* @returns {{headers: {[p: string]: boolean|number|string}, data: *, status: number}}
|
|
8
|
+
*/
|
|
9
|
+
export default function parsePayload<T>(payload: string, validate?: (arg1: T) => void): Response<T>;
|
package/lib/parse-payload.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.default = parsePayload;
|
|
7
4
|
/**
|
|
8
5
|
* Decode the handler response
|
|
@@ -12,16 +9,15 @@ exports.default = parsePayload;
|
|
|
12
9
|
* @returns {{headers: {[p: string]: boolean|number|string}, data: *, status: number}}
|
|
13
10
|
*/
|
|
14
11
|
function parsePayload(payload, validate) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
12
|
+
const proxyResult = JSON.parse(payload);
|
|
13
|
+
if (proxyResult.isBase64Encoded === true) {
|
|
14
|
+
throw new Error("A base64 encoded response from API Gateway handler was received, but is not supported.");
|
|
15
|
+
}
|
|
16
|
+
const data = JSON.parse(proxyResult.body);
|
|
17
|
+
validate?.(data);
|
|
18
|
+
return {
|
|
19
|
+
data,
|
|
20
|
+
status: proxyResult.statusCode,
|
|
21
|
+
headers: proxyResult.headers ?? {},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for parse-payload
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
|
-
import type { ProxyResult } from "@cumulusds/flow-aws-lambda";
|
|
4
8
|
import type { Response } from "./response";
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Decode the handler response
|
|
8
|
-
*
|
|
9
12
|
* @param payload
|
|
10
13
|
* @param validate if given, the validate function is called on the parsed response body. The function should throw an exception if the response is invalid.
|
|
11
|
-
* @returns {{
|
|
14
|
+
* @returns {{
|
|
15
|
+
headers: {
|
|
16
|
+
[p: string]: boolean | number | string,
|
|
17
|
+
},
|
|
18
|
+
data: *,
|
|
19
|
+
status: number,...
|
|
20
|
+
}}
|
|
12
21
|
*/
|
|
13
|
-
export default function parsePayload<T>(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const data: T = JSON.parse(proxyResult.body);
|
|
19
|
-
validate?.(data);
|
|
20
|
-
return {
|
|
21
|
-
data,
|
|
22
|
-
status: proxyResult.statusCode,
|
|
23
|
-
headers: proxyResult.headers ?? {}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
22
|
+
declare export default function parsePayload<T>(
|
|
23
|
+
payload: string,
|
|
24
|
+
validate?: (arg1: T) => void
|
|
25
|
+
): Response<T>;
|
package/lib/response.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/response.js.flow
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for response
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Decoded handler response
|
|
5
10
|
*/
|
|
6
|
-
export type Response<T> = {
|
|
7
|
-
// the response provided by the handler
|
|
11
|
+
export type Response<T> = {
|
|
8
12
|
data: T,
|
|
9
|
-
|
|
10
|
-
// the HTTP status code
|
|
11
13
|
status: number,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
headers: {
|
|
15
|
+
[header: string]: boolean | number | string,
|
|
16
|
+
},
|
|
17
|
+
...
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulusds/aws-apig-bypass",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Client for API Gateway handlers, bypassing API Gateway by directly invoking the Lambda",
|
|
5
5
|
"repository": "https://github.com/CumulusDS/aws-apig-bypass",
|
|
6
6
|
"author": "Cumulus Digital Systems",
|
|
@@ -12,23 +12,21 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"README.md",
|
|
14
14
|
"lib/*",
|
|
15
|
-
"lib/dynamodb/**",
|
|
16
|
-
"lib/services/**",
|
|
17
15
|
"package.json"
|
|
18
16
|
],
|
|
19
17
|
"scripts": {
|
|
20
|
-
"build": "yarn run build:
|
|
21
|
-
"build:
|
|
22
|
-
"build:flow-copy-source": "flow-copy-source --ignore test.js src lib",
|
|
18
|
+
"build": "yarn run build:license-checker && tsc",
|
|
19
|
+
"build:flowtypes": "find lib -type f -name '*.d.ts' -exec sh -c 'yarn flowgen --add-flow-header $1 -o ${1%.*.*}.js.flow' _ '{}' \\;",
|
|
23
20
|
"build:license-checker": "license-checker --csv --out var/licenses.csv",
|
|
24
21
|
"clean": "shx rm -rf lib",
|
|
22
|
+
"flow": "echo this is not a flow project",
|
|
25
23
|
"git:commit": "git add package.json .yarn/versions && git commit -m v${npm_package_version}",
|
|
26
24
|
"git:commit:publish": "git add package.json .yarn/versions/* && git commit -m v${npm_package_version}",
|
|
27
25
|
"git:commit:version": "git add .yarn/versions/* && git commit -m 'Deferred version bump'",
|
|
28
26
|
"git:push": "git push --follow-tags",
|
|
29
27
|
"git:tag": "git tag -a v${npm_package_version} -m v${npm_package_version}",
|
|
30
28
|
"npm:tag:remove": "yarn npm tag remove ${npm_package_name} $0",
|
|
31
|
-
"prepack": "yarn run build",
|
|
29
|
+
"prepack": "yarn run build && yarn run build:flowtypes",
|
|
32
30
|
"prerelease": "yarn version apply && yarn run version:feature $0",
|
|
33
31
|
"publish:patch": "yarn version patch && yarn publish:sync",
|
|
34
32
|
"publish:minor": "yarn version minor && yarn publish:sync",
|
|
@@ -36,14 +34,10 @@
|
|
|
36
34
|
"publish:prepatch": "yarn run version:prepatch && yarn run git:push",
|
|
37
35
|
"publish:prerelease": "yarn npm publish",
|
|
38
36
|
"publish:sync": "yarn run git:commit && yarn run git:tag && yarn git:push",
|
|
39
|
-
"
|
|
40
|
-
"test": "yarn run test:flow && yarn run test:jest && yarn run test:lint && yarn run test:prettier",
|
|
41
|
-
"test:flow": "yarn run test:flow:coverage-report && yarn run test:flow:status",
|
|
42
|
-
"test:flow:coverage-report": "flow-coverage-report -i '{src,test}/**/*.js' -t html -t text --threshold 99 --output-dir var/coverage/flow",
|
|
43
|
-
"test:flow:status": "flow status",
|
|
37
|
+
"test": "yarn run test:jest && yarn run test:lint && yarn run test:prettier",
|
|
44
38
|
"test:jest": "jest --color",
|
|
45
|
-
"test:lint": "eslint
|
|
46
|
-
"test:prettier": "prettier --list-different \"{src,test}/**/*.
|
|
39
|
+
"test:lint": "eslint src/**/*.ts test/**/*.ts",
|
|
40
|
+
"test:prettier": "prettier --list-different \"{src,test}/**/*.ts\"",
|
|
47
41
|
"version:patch": "yarn version --new-version patch",
|
|
48
42
|
"version:minor": "yarn version --new-version minor",
|
|
49
43
|
"version:major": "yarn version --new-version major",
|
|
@@ -55,7 +49,7 @@
|
|
|
55
49
|
"verbose": true,
|
|
56
50
|
"collectCoverage": true,
|
|
57
51
|
"collectCoverageFrom": [
|
|
58
|
-
"src/**/*.
|
|
52
|
+
"src/**/*.ts"
|
|
59
53
|
],
|
|
60
54
|
"testEnvironment": "node",
|
|
61
55
|
"coverageDirectory": "var/coverage/test",
|
|
@@ -69,35 +63,35 @@
|
|
|
69
63
|
}
|
|
70
64
|
},
|
|
71
65
|
"dependencies": {
|
|
72
|
-
"
|
|
66
|
+
"aws-lambda": "^1.0.7",
|
|
67
|
+
"aws-sdk": "^2.1460.0"
|
|
73
68
|
},
|
|
74
69
|
"devDependencies": {
|
|
75
|
-
"@babel/cli": "^7.
|
|
70
|
+
"@babel/cli": "^7.24.7",
|
|
76
71
|
"@babel/core": "^7.7.4",
|
|
77
72
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
|
|
78
73
|
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
|
|
79
74
|
"@babel/preset-env": "^7.0.0",
|
|
80
|
-
"@babel/preset-
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"babel-
|
|
86
|
-
"
|
|
75
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
76
|
+
"@types/aws-lambda": "^8.10.145",
|
|
77
|
+
"@types/jest": "^29.5.13",
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^8.7.0",
|
|
79
|
+
"@typescript-eslint/parser": "^8.7.0",
|
|
80
|
+
"babel-eslint": "^10.1.0",
|
|
81
|
+
"babel-jest": "^29.7.0",
|
|
82
|
+
"eslint": "^8.57.1",
|
|
87
83
|
"eslint-config-airbnb-base": "14.0.0",
|
|
88
|
-
"eslint-config-prettier": "^
|
|
89
|
-
"eslint-plugin-
|
|
90
|
-
"eslint-plugin-
|
|
91
|
-
"eslint-plugin-
|
|
92
|
-
"
|
|
93
|
-
"flow-bin": "^0.142.0",
|
|
94
|
-
"flow-copy-source": "^2.0.9",
|
|
95
|
-
"flow-typed": "^3.9.0",
|
|
84
|
+
"eslint-config-prettier": "^8.10.0",
|
|
85
|
+
"eslint-plugin-import": "^2.18.2",
|
|
86
|
+
"eslint-plugin-jest": "^28.8.3",
|
|
87
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
88
|
+
"flowgen": "^1.21.0",
|
|
96
89
|
"git-describe": "^4.0.4",
|
|
97
90
|
"jest": "^29.7.0",
|
|
98
91
|
"license-checker": "^25.0.1",
|
|
99
|
-
"prettier": "^
|
|
100
|
-
"shx": "^0.3.2"
|
|
92
|
+
"prettier": "^3.3.3",
|
|
93
|
+
"shx": "^0.3.2",
|
|
94
|
+
"typescript": "^5.6.2"
|
|
101
95
|
},
|
|
102
96
|
"packageManager": "yarn@3.5.0"
|
|
103
97
|
}
|