Skip to content

Commit 17230ee

Browse files
author
Nghĩa Nguyễn Ngọc
committed
fix(events): correct CodePipelineEventBridge version field types
The AWS service team confirmed the correct types for version fields in CodePipelineCloudWatchEvent (issue #552): - .version (top level): string -- already correct - .detail.version: numeric -- was int64, now json.Number - .detail.type.version: string -- was int64, now string The previous int64 types caused UnmarshalTypeError at runtime when AWS sent detail.version as a float (e.g. 2.0) or detail.type.version as a quoted string (e.g. "1"). json.Number is used for detail.version to handle both integer and float representations without losing the raw value. Test fixture updated to reflect real AWS payload format, and a new fixture added to cover the float version regression case. Fixes #552
1 parent 815d21f commit 17230ee

4 files changed

Lines changed: 70 additions & 9 deletions

events/codepipeline_cloudwatch.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package events
22

33
import (
4+
"encoding/json"
45
"time"
56
)
67

@@ -79,8 +80,9 @@ type CodePipelineEventBridgeEvent = CodePipelineCloudWatchEvent
7980
type CodePipelineEventDetail struct {
8081
Pipeline string `json:"pipeline"`
8182

82-
// From live testing this is always int64 not string as documented
83-
Version int64 `json:"version"`
83+
// Version is numeric. AWS may send integer (1) or float (2.0) depending on the event.
84+
// json.Number preserves the raw value and allows callers to convert as needed.
85+
Version json.Number `json:"version"`
8486

8587
ExecutionID string `json:"execution-id"`
8688

@@ -104,8 +106,8 @@ type CodePipelineEventDetailType struct {
104106

105107
Provider string `json:"provider"`
106108

107-
// From published EventBridge schema registry this is always int64 not string as documented
108-
Version int64 `json:"version"`
109+
// Version is a string per the AWS EventBridge schema registry and confirmed by the service team.
110+
Version string `json:"version"`
109111
}
110112

111113
type CodePipelineEventDetailExecutionResult struct {

events/codepipeline_cloudwatch_test.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
2929
},
3030
Detail: CodePipelineEventDetail{
3131
Pipeline: "myPipeline",
32-
Version: 1,
32+
Version: "1",
3333
ExecutionID: "01234567-0123-0123-0123-012345678901",
3434
Stage: "Prod",
3535
Action: "myAction",
@@ -39,7 +39,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
3939
Owner: "AWS",
4040
Category: "Deploy",
4141
Provider: "CodeDeploy",
42-
Version: 1,
42+
Version: "1",
4343
},
4444
},
4545
},
@@ -59,7 +59,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
5959
},
6060
Detail: CodePipelineEventDetail{
6161
Pipeline: "myPipeline",
62-
Version: 1,
62+
Version: "1",
6363
ExecutionID: "01234567-0123-0123-0123-012345678901",
6464
State: "STARTED",
6565
},
@@ -80,12 +80,44 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) {
8080
},
8181
Detail: CodePipelineEventDetail{
8282
Pipeline: "myPipeline",
83-
Version: 1,
83+
Version: "1",
8484
ExecutionID: "01234567-0123-0123-0123-012345678901",
8585
State: "STARTED",
8686
},
8787
},
8888
},
89+
{
90+
// AWS may send detail.version as a float (e.g. 2.0) rather than an integer.
91+
// Regression test for https://github.com/aws/aws-lambda-go/issues/552
92+
input: "testdata/codepipeline-action-execution-stage-change-event-float-version.json",
93+
expect: CodePipelineCloudWatchEvent{
94+
Version: "0",
95+
ID: "CWE-event-id",
96+
DetailType: "CodePipeline Action Execution State Change",
97+
Source: "aws.codepipeline",
98+
AccountID: "123456789012",
99+
Time: time.Date(2017, 04, 22, 3, 31, 47, 0, time.UTC),
100+
Region: "us-east-1",
101+
Resources: []string{
102+
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline",
103+
},
104+
Detail: CodePipelineEventDetail{
105+
Pipeline: "myPipeline",
106+
Version: "2.0",
107+
ExecutionID: "01234567-0123-0123-0123-012345678901",
108+
Stage: "Prod",
109+
Action: "myAction",
110+
State: "STARTED",
111+
Region: "us-west-2",
112+
Type: CodePipelineEventDetailType{
113+
Owner: "AWS",
114+
Category: "Deploy",
115+
Provider: "CodeDeploy",
116+
Version: "1",
117+
},
118+
},
119+
},
120+
},
89121
}
90122

91123
for _, testcase := range tests {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "0",
3+
"id": "CWE-event-id",
4+
"detail-type": "CodePipeline Action Execution State Change",
5+
"source": "aws.codepipeline",
6+
"account": "123456789012",
7+
"time": "2017-04-22T03:31:47Z",
8+
"region": "us-east-1",
9+
"resources": [
10+
"arn:aws:codepipeline:us-east-1:123456789012:pipeline:myPipeline"
11+
],
12+
"detail": {
13+
"pipeline": "myPipeline",
14+
"version": 2.0,
15+
"execution-id": "01234567-0123-0123-0123-012345678901",
16+
"stage": "Prod",
17+
"action": "myAction",
18+
"state": "STARTED",
19+
"region":"us-west-2",
20+
"type": {
21+
"owner": "AWS",
22+
"category": "Deploy",
23+
"provider": "CodeDeploy",
24+
"version": "1"
25+
}
26+
}
27+
}

events/testdata/codepipeline-action-execution-stage-change-event.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"owner": "AWS",
2222
"category": "Deploy",
2323
"provider": "CodeDeploy",
24-
"version": 1
24+
"version": "1"
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)