Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#21081 from daniel-cottone/update-a…
Browse files Browse the repository at this point in the history
…ws-lambda-custom-auth-event

[@types/aws-lambda] Updating CustomAuthorizerEvent for request type
  • Loading branch information
rbuckton authored Oct 31, 2017
2 parents 7141277 + 19ab2f1 commit 3518a05
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 52 deletions.
64 changes: 36 additions & 28 deletions types/aws-lambda/aws-lambda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var anyObj: any = { abc: 123 };
var num: number = 5;
var error: Error = new Error();
var b: boolean = true;
var apiGwEvtReqCtx: AWSLambda.APIGatewayEventRequestContext;
var apiGwEvt: AWSLambda.APIGatewayEvent;
var customAuthorizerEvt: AWSLambda.CustomAuthorizerEvent;
var clientCtx: AWSLambda.ClientContext;
Expand All @@ -22,33 +23,33 @@ var snsEvtRec: AWSLambda.SNSEventRecord;
var snsMsg: AWSLambda.SNSMessage;
var snsMsgAttr: AWSLambda.SNSMessageAttribute;
var snsMsgAttrs: AWSLambda.SNSMessageAttributes;
var S3EvtRec: AWSLambda.S3EventRecord = {
var S3EvtRec: AWSLambda.S3EventRecord = {
eventVersion: '2.0',
eventSource: 'aws:s3',
awsRegion: 'us-east-1',
eventTime: '1970-01-01T00:00:00.000Z',
eventName: 'ObjectCreated:Put',
userIdentity: {
userIdentity: {
principalId: 'AIDAJDPLRKLG7UEXAMPLE'
},
requestParameters:{
requestParameters:{
sourceIPAddress: '127.0.0.1'
},
responseElements: {
responseElements: {
'x-amz-request-id': 'C3D13FE58DE4C810',
'x-amz-id-2': 'FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD'
},
s3: {
s3: {
s3SchemaVersion: '1.0',
configurationId: 'testConfigRule',
bucket: {
bucket: {
name: 'mybucket',
ownerIdentity: {
ownerIdentity: {
principalId: 'A3NL1KOZZKExample'
},
arn: 'arn:aws:s3:::mybucket'
},
object: {
object: {
key: 'HappyFace.jpg',
size: 1024,
eTag: 'd41d8cd98f00b204e9800998ecf8427e',
Expand All @@ -65,6 +66,27 @@ var cognitoUserPoolEvent: AWSLambda.CognitoUserPoolEvent;
var cloudformationCustomResourceEvent: AWSLambda.CloudFormationCustomResourceEvent;
var cloudformationCustomResourceResponse: AWSLambda.CloudFormationCustomResourceResponse;

/* API Gateway Event request context */
str = apiGwEvtReqCtx.accountId;
str = apiGwEvtReqCtx.apiId;
str = apiGwEvtReqCtx.httpMethod;
str = apiGwEvtReqCtx.identity.accessKey;
str = apiGwEvtReqCtx.identity.accountId;
str = apiGwEvtReqCtx.identity.apiKey;
str = apiGwEvtReqCtx.identity.caller;
str = apiGwEvtReqCtx.identity.cognitoAuthenticationProvider;
str = apiGwEvtReqCtx.identity.cognitoAuthenticationType;
str = apiGwEvtReqCtx.identity.cognitoIdentityId;
str = apiGwEvtReqCtx.identity.cognitoIdentityPoolId;
str = apiGwEvtReqCtx.identity.sourceIp;
str = apiGwEvtReqCtx.identity.user;
str = apiGwEvtReqCtx.identity.userAgent;
str = apiGwEvtReqCtx.identity.userArn;
str = apiGwEvtReqCtx.stage;
str = apiGwEvtReqCtx.requestId;
str = apiGwEvtReqCtx.resourceId;
str = apiGwEvtReqCtx.resourcePath;

/* API Gateway Event */
str = apiGwEvt.body;
str = apiGwEvt.headers["example"];
Expand All @@ -74,31 +96,17 @@ str = apiGwEvt.path;
str = apiGwEvt.pathParameters["example"];
str = apiGwEvt.queryStringParameters["example"];
str = apiGwEvt.stageVariables["example"];
str = apiGwEvt.requestContext.accountId;
str = apiGwEvt.requestContext.apiId;
str = apiGwEvt.requestContext.httpMethod;
str = apiGwEvt.requestContext.identity.accessKey;
str = apiGwEvt.requestContext.identity.accountId;
str = apiGwEvt.requestContext.identity.apiKey;
str = apiGwEvt.requestContext.identity.caller;
str = apiGwEvt.requestContext.identity.cognitoAuthenticationProvider;
str = apiGwEvt.requestContext.identity.cognitoAuthenticationType;
str = apiGwEvt.requestContext.identity.cognitoIdentityId;
str = apiGwEvt.requestContext.identity.cognitoIdentityPoolId;
str = apiGwEvt.requestContext.identity.sourceIp;
str = apiGwEvt.requestContext.identity.user;
str = apiGwEvt.requestContext.identity.userAgent;
str = apiGwEvt.requestContext.identity.userArn;
str = apiGwEvt.requestContext.stage;
str = apiGwEvt.requestContext.requestId;
str = apiGwEvt.requestContext.resourceId;
str = apiGwEvt.requestContext.resourcePath;
apiGwEvtReqCtx = apiGwEvt.requestContext;
str = apiGwEvt.resource;

/* API Gateway CustomAuthorizer Event */
str = customAuthorizerEvt.type;
str = customAuthorizerEvt.authorizationToken;
str = customAuthorizerEvt.methodArn;
str = customAuthorizerEvt.authorizationToken;
str = apiGwEvt.pathParameters["example"];
str = apiGwEvt.queryStringParameters["example"];
str = apiGwEvt.stageVariables["example"];
apiGwEvtReqCtx = apiGwEvt.requestContext;

/* SNS Event */
snsEvtRecs = snsEvt.Records;
Expand Down
56 changes: 32 additions & 24 deletions types/aws-lambda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,35 @@
// Yoriki Yamaguchi <https://github.com/y13i>
// wwwy3y3 <https://github.com/wwwy3y3>
// Ishaan Malhi <https://github.com/OrthoDex>
// Daniel Cottone <https://github.com/daniel-cottone>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

// API Gateway "event" request context
interface APIGatewayEventRequestContext {
accountId: string;
apiId: string;
httpMethod: string;
identity: {
accessKey: string | null;
accountId: string | null;
apiKey: string | null;
caller: string | null;
cognitoAuthenticationProvider: string | null;
cognitoAuthenticationType: string | null;
cognitoIdentityId: string | null;
cognitoIdentityPoolId: string | null;
sourceIp: string;
user: string | null;
userAgent: string | null;
userArn: string | null;
},
stage: string;
requestId: string;
resourceId: string;
resourcePath: string;
}

// API Gateway "event"
interface APIGatewayEvent {
body: string | null;
Expand All @@ -21,37 +47,19 @@ interface APIGatewayEvent {
pathParameters: { [name: string]: string } | null;
queryStringParameters: { [name: string]: string } | null;
stageVariables: { [name: string]: string } | null;
requestContext: {
accountId: string;
apiId: string;
httpMethod: string;
identity: {
accessKey: string | null;
accountId: string | null;
apiKey: string | null;
caller: string | null;
cognitoAuthenticationProvider: string | null;
cognitoAuthenticationType: string | null;
cognitoIdentityId: string | null;
cognitoIdentityPoolId: string | null;
sourceIp: string;
user: string | null;
userAgent: string | null;
userArn: string | null;
},
stage: string;
requestId: string;
resourceId: string;
resourcePath: string;
};
requestContext: APIGatewayEventRequestContext;
resource: string;
}

// API Gateway CustomAuthorizer "event"
interface CustomAuthorizerEvent {
type: string;
authorizationToken: string;
methodArn: string;
authorizationToken?: string;
headers?: { [name: string]: string };
pathParameters?: { [name: string]: string } | null;
queryStringParameters?: { [name: string]: string } | null;
requestContext?: APIGatewayEventRequestContext;
}

// SNS "event"
Expand Down

0 comments on commit 3518a05

Please sign in to comment.