mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
@types/aws-lambda: There are no types for the communication with Application Load Balancer (#33763)
* Add the additional types for the usage of Application Load Balancer * Change the long name "Application Load Balancer" to shorter one "ALB" * Add ALBCallback for the completeness of the communication with the ALB
This commit is contained in:
committed by
Wesley Wigham
parent
128b735ca0
commit
3eb866bd83
@@ -8,10 +8,14 @@ declare let num: number;
|
||||
declare let error: Error;
|
||||
declare let bool: boolean;
|
||||
declare let boolOrUndefined: boolean | undefined;
|
||||
declare let boolOrNumOrStr: boolean | number | string;
|
||||
declare let numOrUndefined: number | undefined;
|
||||
declare let apiGwEvtReqCtx: AWSLambda.APIGatewayEventRequestContext;
|
||||
declare let apiGwEvtReqCtxOpt: AWSLambda.APIGatewayEventRequestContext | null | undefined;
|
||||
declare let apiGwEvt: AWSLambda.APIGatewayEvent;
|
||||
declare let albEvtReqCtx: AWSLambda.ALBEventRequestContext;
|
||||
declare let albEvt: AWSLambda.ALBEvent;
|
||||
declare let albRes: AWSLambda.ALBResult;
|
||||
declare let customAuthorizerEvt: AWSLambda.CustomAuthorizerEvent;
|
||||
declare let clientCtx: AWSLambda.ClientContext;
|
||||
declare let clientCtxOrUndefined: AWSLambda.ClientContext | undefined;
|
||||
@@ -125,6 +129,27 @@ str = apiGwEvt.stageVariables!["example"];
|
||||
apiGwEvtReqCtx = apiGwEvt.requestContext;
|
||||
str = apiGwEvt.resource;
|
||||
|
||||
/* Application Load Balancer Event Request Context */
|
||||
str = albEvtReqCtx.elb.targetGroupArn;
|
||||
|
||||
/* Application Load Balancer Event */
|
||||
str = albEvt.httpMethod;
|
||||
str = albEvt.path;
|
||||
str = albEvt.queryStringParameters!["example"];
|
||||
str = albEvt.headers!["example"];
|
||||
str = albEvt.multiValueQueryStringParameters!["example"][0];
|
||||
str = albEvt.multiValueHeaders!["example"][0];
|
||||
strOrNull = albEvt.body;
|
||||
bool = albEvt.isBase64Encoded;
|
||||
|
||||
/* Application Load Balancer Result */
|
||||
num = albRes.statusCode;
|
||||
str = albRes.statusDescription;
|
||||
boolOrNumOrStr = albRes.headers!["example"];
|
||||
boolOrNumOrStr = albRes.multiValueHeaders!["example"][0];
|
||||
str = albRes.body;
|
||||
bool = albRes.isBase64Encoded;
|
||||
|
||||
/* API Gateway CustomAuthorizer Event */
|
||||
str = customAuthorizerEvt.type;
|
||||
str = customAuthorizerEvt.methodArn;
|
||||
@@ -879,6 +904,33 @@ const inferredHandler: AWSLambda.S3Handler = (event, context, cb) => {
|
||||
// Test using default Callback type still works.
|
||||
const defaultCallbackHandler: AWSLambda.APIGatewayProxyHandler = (event: AWSLambda.APIGatewayEvent, context: AWSLambda.Context, cb: AWSLambda.Callback) => { };
|
||||
|
||||
const albSyncHandler: AWSLambda.ALBHandler = (
|
||||
event: AWSLambda.ALBEvent,
|
||||
context: AWSLambda.Context,
|
||||
cb: AWSLambda.ALBCallback,
|
||||
) => {
|
||||
cb(null, {
|
||||
statusCode: 200,
|
||||
statusDescription: '200 OK',
|
||||
headers: { },
|
||||
body: '',
|
||||
isBase64Encoded: false,
|
||||
});
|
||||
};
|
||||
const albAsyncHandler: AWSLambda.ALBHandler = async (
|
||||
event: AWSLambda.ALBEvent,
|
||||
context: AWSLambda.Context,
|
||||
cb: AWSLambda.ALBCallback,
|
||||
) => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
statusDescription: '200 OK',
|
||||
headers: { },
|
||||
body: '',
|
||||
isBase64Encoded: false,
|
||||
};
|
||||
};
|
||||
|
||||
// Specific types
|
||||
let s3Handler: AWSLambda.S3Handler = (event: AWSLambda.S3Event, context: AWSLambda.Context, cb: AWSLambda.Callback<void>) => {};
|
||||
// Test old name
|
||||
|
||||
31
types/aws-lambda/index.d.ts
vendored
31
types/aws-lambda/index.d.ts
vendored
@@ -28,6 +28,7 @@
|
||||
// Loïk Gaonac'h <https://github.com/loikg>
|
||||
// Roberto Zen <https://github.com/skyzenr>
|
||||
// Richard Cornelissen <https://github.com/richardcornelissen>
|
||||
// Grzegorz Redlicki <https://github.com/redlickigrzegorz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -86,6 +87,24 @@ export interface APIGatewayProxyEvent {
|
||||
}
|
||||
export type APIGatewayEvent = APIGatewayProxyEvent; // Old name
|
||||
|
||||
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
|
||||
export interface ALBEventRequestContext {
|
||||
elb: {
|
||||
targetGroupArn: string;
|
||||
};
|
||||
}
|
||||
export interface ALBEvent {
|
||||
requestContext: ALBEventRequestContext;
|
||||
httpMethod: string;
|
||||
path: string;
|
||||
queryStringParameters?: { [parameter: string]: string }; // URL encoded
|
||||
headers?: { [header: string]: string };
|
||||
multiValueQueryStringParameters?: { [parameter: string]: string[] }; // URL encoded
|
||||
multiValueHeaders?: { [header: string]: string[] };
|
||||
body: string | null;
|
||||
isBase64Encoded: boolean;
|
||||
}
|
||||
|
||||
// API Gateway CustomAuthorizer "event"
|
||||
export interface CustomAuthorizerEvent {
|
||||
type: string;
|
||||
@@ -474,6 +493,15 @@ export interface APIGatewayProxyResult {
|
||||
}
|
||||
export type ProxyResult = APIGatewayProxyResult; // Old name
|
||||
|
||||
export interface ALBResult {
|
||||
statusCode: number;
|
||||
statusDescription: string;
|
||||
headers?: { [header: string]: boolean | number | string };
|
||||
multiValueHeaders?: { [header: string]: Array<boolean | number | string> };
|
||||
body: string;
|
||||
isBase64Encoded: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* API Gateway CustomAuthorizer AuthResponse.
|
||||
* http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#api-gateway-custom-authorizer-output
|
||||
@@ -1058,6 +1086,9 @@ export type APIGatewayProxyCallback = Callback<APIGatewayProxyResult>;
|
||||
export type ProxyHandler = APIGatewayProxyHandler; // Old name
|
||||
export type ProxyCallback = APIGatewayProxyCallback; // Old name
|
||||
|
||||
export type ALBHandler = Handler<ALBEvent, ALBResult>;
|
||||
export type ALBCallback = Callback<ALBResult>;
|
||||
|
||||
// TODO: IoT
|
||||
|
||||
export type CodePipelineHandler = Handler<CodePipelineEvent, void>;
|
||||
|
||||
Reference in New Issue
Block a user