From a05670526496ed56ac6c20a74fa12895fe5755b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 12 Dec 2018 16:14:18 +0100 Subject: [PATCH 1/5] Add CloudWatch events for CodePipeline Add AWS lambda event type definitions for https://docs.aws.amazon.com/codepipeline/latest/userguide/detect-state-changes-cloudwatch-events.html --- types/aws-lambda/aws-lambda-tests.ts | 21 ++++++ types/aws-lambda/index.d.ts | 104 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 00b71132e9..566e01c592 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -599,6 +599,27 @@ const CodePipelineEvent: AWSLambda.CodePipelineEvent = { CodePipelineEvent["CodePipeline.job"].data.encryptionKey = { type: 'KMS', id: 'key' }; +/* CodePipeline CloudWatch Events + * see https://docs.aws.amazon.com/codepipeline/latest/userguide/detect-state-changes-cloudwatch-events.html + * Their documentation says that detail.version is a string, but it is actually an integer + */ +const CodePipelineCloudWatchEvent: AWSLambda.CodePipelineCloudWatchEvent = { + version: '0', + id: 'event_Id', + 'detail-type': 'CodePipeline Pipeline Execution State Change', + source: 'aws.codepipeline', + account: 'Pipeline_Account', + time: 'TimeStamp', + region: 'us-east-1', + resources: ['arn:aws:codepipeline:us-east-1:account_ID:myPipeline'], + detail: { + pipeline: 'myPipeline', + version: 1, + state: 'STARTED', + 'execution-id': 'execution_Id', + }, +}; + /* CloudFront events, see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html */ const CloudFrontRequestWithCustomOriginEvent: AWSLambda.CloudFrontRequestEvent = { Records: [ diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index d9d22f8c65..df0b331c66 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -24,6 +24,7 @@ // Oliver Hookins // Trevor Leach // James Gregory +// Erik Dalén // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -576,6 +577,109 @@ export interface CodePipelineEvent { }; } +/** + * CodePipeline CloudWatch Events + * https://docs.aws.amazon.com/codepipeline/latest/userguide/detect-state-changes-cloudwatch-events.html + * + * The above CodePipelineEvent is when a lambda is invoked by a CodePipeline. + * These events are when you subsribe to CodePipeline events in CloudWatch. + * + * Their documentation says that detail.version is a string, but it is actually an integer + */ +export type CodePipelineState = + | 'STARTED' + | 'SUCCEEDED' + | 'RESUMED' + | 'FAILED' + | 'CANCELED' + | 'SUPERSEDED'; + +export type CodePipelineStageState = + | 'STARTED' + | 'SUCCEEDED' + | 'RESUMED' + | 'FAILED' + | 'CANCELED'; + +export type CodePipelineActionState = + | 'STARTED' + | 'SUCCEEDED' + | 'FAILED' + | 'CANCELED'; + +export interface CodePipelinePiplelineEvent { + version: string; + id: string; + 'detail-type': 'CodePipeline Pipeline Execution State Change'; + source: 'aws.codepipeline'; + account: string; + time: string; + region: string; + resources: string[]; + detail: { + pipeline: string; + version: number; + state: CodePipelineState; + 'execution-id': string; + }; +} + +export interface CodePipelineStageEvent { + version: string; + id: string; + 'detail-type': 'CodePipeline Stage Execution State Change'; + source: 'aws.codepipeline'; + account: string; + time: string; + region: string; + resources: string[]; + detail: { + pipeline: string; + version: number; + 'execution-id': string; + stage: string; + state: CodePipelineStageState; + }; +} + +export type CodePipelineActionCategory = + | 'Approval' + | 'Build' + | 'Deploy' + | 'Invoke' + | 'Source' + | 'Test'; + +export interface CodePipelineActionEvent { + version: string; + id: string; + 'detail-type': 'CodePipeline Action Execution State Change'; + source: 'aws.codepipeline'; + account: string; + time: string; + region: string; + resources: string[]; + detail: { + pipeline: string; + version: number; + 'execution-id': string; + stage: string; + action: string; + state: CodePipelineActionState; + type: { + owner: 'AWS' | 'Custom' | 'ThirdParty'; + category: CodePipelineActionCategory; + provider: 'CodeDeploy'; + version: number; + }; + }; +} + +export type CodePipelineCloudWatchEvent = + | CodePipelinePiplelineEvent + | CodePipelineStageEvent + | CodePipelineActionEvent; + /** * CloudFront events * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html From c87266f6607b5a481749babd69251e2a60c71b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Thu, 13 Dec 2018 10:03:00 +0100 Subject: [PATCH 2/5] Fix typo --- types/aws-lambda/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index df0b331c66..c750bee53b 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -607,7 +607,7 @@ export type CodePipelineActionState = | 'FAILED' | 'CANCELED'; -export interface CodePipelinePiplelineEvent { +export interface CodePipelinePipelineEvent { version: string; id: string; 'detail-type': 'CodePipeline Pipeline Execution State Change'; @@ -676,7 +676,7 @@ export interface CodePipelineActionEvent { } export type CodePipelineCloudWatchEvent = - | CodePipelinePiplelineEvent + | CodePipelinePipelineEvent | CodePipelineStageEvent | CodePipelineActionEvent; From ff933f81c4d66f78e49ad59c928f64ec00dc91ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Thu, 13 Dec 2018 10:24:45 +0100 Subject: [PATCH 3/5] Change value of provider key to string --- types/aws-lambda/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index c750bee53b..15f6375884 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -669,7 +669,7 @@ export interface CodePipelineActionEvent { type: { owner: 'AWS' | 'Custom' | 'ThirdParty'; category: CodePipelineActionCategory; - provider: 'CodeDeploy'; + provider: string; version: number; }; }; From 0fd1512fdf5009dd0ce523e0327db3dce5555a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Thu, 13 Dec 2018 10:27:38 +0100 Subject: [PATCH 4/5] Rename all cloudwatch codepipeline events to include cloudwatch in name --- types/aws-lambda/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index 15f6375884..94aa592c11 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -607,7 +607,7 @@ export type CodePipelineActionState = | 'FAILED' | 'CANCELED'; -export interface CodePipelinePipelineEvent { +export interface CodePipelineCloudWatchPipelineEvent { version: string; id: string; 'detail-type': 'CodePipeline Pipeline Execution State Change'; @@ -624,7 +624,7 @@ export interface CodePipelinePipelineEvent { }; } -export interface CodePipelineStageEvent { +export interface CodePipelineCloudWatchStageEvent { version: string; id: string; 'detail-type': 'CodePipeline Stage Execution State Change'; @@ -650,7 +650,7 @@ export type CodePipelineActionCategory = | 'Source' | 'Test'; -export interface CodePipelineActionEvent { +export interface CodePipelineCloudWatchActionEvent { version: string; id: string; 'detail-type': 'CodePipeline Action Execution State Change'; @@ -676,9 +676,9 @@ export interface CodePipelineActionEvent { } export type CodePipelineCloudWatchEvent = - | CodePipelinePipelineEvent - | CodePipelineStageEvent - | CodePipelineActionEvent; + | CodePipelineCloudWatchPipelineEvent + | CodePipelineCloudWatchStageEvent + | CodePipelineCloudWatchActionEvent; /** * CloudFront events From 8c536fe7db527ae445940f0f4f92979d74e1f4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Thu, 13 Dec 2018 10:34:16 +0100 Subject: [PATCH 5/5] Add handler definitions for codepipeline cloudwatch events --- types/aws-lambda/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index 94aa592c11..799f9062fd 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -941,6 +941,11 @@ export type ProxyCallback = APIGatewayProxyCallback; // Old name export type CodePipelineHandler = Handler; +export type CodePipelineCloudWatchHandler = Handler; +export type CodePipelineCloudWatchPipelineHandler = Handler; +export type CodePipelineCloudWatchStageHandler = Handler; +export type CodePipelineCloudWatchActionHandler = Handler; + export type CloudFrontRequestHandler = Handler; export type CloudFrontRequestCallback = Callback;