Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions events/codepipeline_cloudwatch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events

import (
"encoding/json"
"time"
)

Expand Down Expand Up @@ -79,8 +80,9 @@ type CodePipelineEventBridgeEvent = CodePipelineCloudWatchEvent
type CodePipelineEventDetail struct {
Pipeline string `json:"pipeline"`

// From live testing this is always int64 not string as documented
Version int64 `json:"version"`
// Version is the pipeline version number. AWS may send this as an integer (e.g. 1)
// or a float (e.g. 2.0). Use Version.Int64() or Version.Float64() to extract the value.
Version json.Number `json:"version"`

ExecutionID string `json:"execution-id"`

Expand All @@ -104,8 +106,8 @@ type CodePipelineEventDetailType struct {

Provider string `json:"provider"`

// From published EventBridge schema registry this is always int64 not string as documented
Version int64 `json:"version"`
// Version is a string per the AWS EventBridge schema registry and confirmed by the service team.
Version string `json:"version"`
}

type CodePipelineEventDetailExecutionResult struct {
Expand Down
40 changes: 36 additions & 4 deletions events/codepipeline_cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
Version: "1",
ExecutionID: "01234567-0123-0123-0123-012345678901",
Stage: "Prod",
Action: "myAction",
Expand All @@ -39,7 +39,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
Owner: "AWS",
Category: "Deploy",
Provider: "CodeDeploy",
Version: 1,
Version: "1",
},
},
},
Expand All @@ -59,7 +59,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
Version: "1",
ExecutionID: "01234567-0123-0123-0123-012345678901",
State: "STARTED",
},
Expand All @@ -80,12 +80,44 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: 1,
Version: "1",
ExecutionID: "01234567-0123-0123-0123-012345678901",
State: "STARTED",
},
},
},
{
// AWS may send detail.version as a float (e.g. 2.0) rather than an integer.
// Regression test for https://github.com/aws/aws-lambda-go/issues/552
input: "testdata/codepipeline-action-execution-stage-change-event-float-version.json",
expect: CodePipelineCloudWatchEvent{
Version: "0",
ID: "CWE-event-id",
DetailType: "CodePipeline Action Execution State Change",
Source: "aws.codepipeline",
AccountID: "123456789012",
Time: time.Date(2017, 04, 22, 3, 31, 47, 0, time.UTC),
Region: "us-east-1",
Resources: []string{
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline",
},
Detail: CodePipelineEventDetail{
Pipeline: "myPipeline",
Version: "2.0",
ExecutionID: "01234567-0123-0123-0123-012345678901",
Stage: "Prod",
Action: "myAction",
State: "STARTED",
Region: "us-west-2",
Type: CodePipelineEventDetailType{
Owner: "AWS",
Category: "Deploy",
Provider: "CodeDeploy",
Version: "1",
},
},
},
},
}

for _, testcase := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "0",
"id": "CWE-event-id",
"detail-type": "CodePipeline Action Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2017-04-22T03:31:47Z",
"region": "us-east-1",
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"version": 2.0,
"execution-id": "01234567-0123-0123-0123-012345678901",
"stage": "Prod",
"action": "myAction",
"state": "STARTED",
"region":"us-west-2",
"type": {
"owner": "AWS",
"category": "Deploy",
"provider": "CodeDeploy",
"version": "1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"owner": "AWS",
"category": "Deploy",
"provider": "CodeDeploy",
"version": 1
"version": "1"
}
}
}
Loading