From b2517cc5cf8d37f9e30502aaf88fffca21b3c0cb Mon Sep 17 00:00:00 2001 From: Jamie Starke Date: Tue, 2 Jan 2018 15:47:47 -0800 Subject: [PATCH] Adds typing for CloudWatch Logs events (#21239) --- types/aws-lambda/aws-lambda-tests.ts | 14 +++++++++++++ types/aws-lambda/index.d.ts | 31 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 7cd969b6c6..d807587824 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -65,6 +65,8 @@ var S3CreateEvent: AWSLambda.S3CreateEvent = { var cognitoUserPoolEvent: AWSLambda.CognitoUserPoolEvent; var cloudformationCustomResourceEvent: AWSLambda.CloudFormationCustomResourceEvent; var cloudformationCustomResourceResponse: AWSLambda.CloudFormationCustomResourceResponse; +var cloudwatchLogsEvent: AWSLambda.CloudWatchLogsEvent; +var cloudwatchLogsDecodedData: AWSLambda.CloudWatchLogsDecodedData; /* API Gateway Event request context */ str = apiGwEvtReqCtx.accountId; @@ -364,6 +366,18 @@ clientCtx = context.clientContext; str = identity.cognitoIdentityId; str = identity.cognitoIdentityPoolId; +/* CloudWatch Logs */ +str = cloudwatchLogsEvent.awslogs.data; + +str = cloudwatchLogsDecodedData.owner; +str = cloudwatchLogsDecodedData.logGroup; +str = cloudwatchLogsDecodedData.logStream; +str = cloudwatchLogsDecodedData.subscriptionFilters[0]; +str = cloudwatchLogsDecodedData.messageType; +str = cloudwatchLogsDecodedData.logEvents[0].id; +num = cloudwatchLogsDecodedData.logEvents[0].timestamp; +str = cloudwatchLogsDecodedData.logEvents[0].message; + /* ClientContext */ clientContextClient = clientCtx.client; anyObj = clientCtx.Custom; diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index 172ee69210..fd0b87a19d 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -294,6 +294,37 @@ type CloudFormationCustomResourceFailedResponse = CloudFormationCustomResourceRe export type CloudFormationCustomResourceResponse = CloudFormationCustomResourceSuccessResponse | CloudFormationCustomResourceFailedResponse; +/** + * See http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-cloudwatch-logs + */ +interface CloudWatchLogsEvent { + awslogs: CloudWatchLogsEventData; +} + +interface CloudWatchLogsEventData { + data: string; +} + +interface CloudWatchLogsDecodedData { + owner: string; + logGroup: string; + logStream: string; + subscriptionFilters: string[]; + messageType: string; + logEvents: CloudWatchLogsLogEvent[]; +} + +/** + * See http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#LambdaFunctionExample + */ +interface CloudWatchLogsLogEvent { + id: string; + timestamp: number; + message: string; +} + + + // Context // http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html interface Context {