Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmarshalTypeError on CodePipelineEventBridgeEvent #552

Open
lexedwards opened this issue Feb 23, 2024 · 4 comments
Open

UnmarshalTypeError on CodePipelineEventBridgeEvent #552

lexedwards opened this issue Feb 23, 2024 · 4 comments
Labels
bug type/events issue or feature request related to the events package

Comments

@lexedwards
Copy link

Is your feature request related to a problem? Please describe.

Triggering a lambda with EventBridge CodePipeline events, i.e.:

{
  "detail-type": [
    "CodePipeline Pipeline Execution State Change",
    "CodePipeline Stage Execution State Change",
    "CodePipeline Action Execution State Change"
  ],
  "source": [
    "aws.codepipeline"
  ]
}

The Lambda in question has this structure:

func handler(_ context.Context, event *events.CodePipelineEventBridgeEvent) error {}

Upon execution, it almost immediately fails and outputs one of two errors (so far):

json: cannot unmarshal number 2.0 into Go struct field CodePipelineEventDetail.detail.version of type int64
json: cannot unmarshal string into Go struct field CodePipelineEventDetailType.detail.type.version of type int64

Describe the solution you'd like

I'm fairly certain I'm using the correct event type here, but I could be wrong. However, I'd like a solution to the lambda not failing immediately and the type being correct for what EventBridge is passing into the lambda.

@bmoffatt
Copy link
Collaborator

Original PR called out a documentation inconsistency regarding these fields. https://github.com/aws/aws-lambda-go/pull/247/files

I wonder if something changed recently!

@bmoffatt bmoffatt added stage/more-info-needed type/events issue or feature request related to the events package troubleshooting bug labels Feb 24, 2024
@lexedwards
Copy link
Author

I haven't been using this particular event with Go, so I can't really comment on how recent the change has been, however, after some experimenting, I've seen it reliably work with some alterations to the type declared:

https://github.com/aws/aws-lambda-go/blob/de51f6811a68226f2238b77fd74b84df29c446f4/events/codepipeline_cloudwatch.go#L79C1-L83C32

L83's Version type as json.Number - Though, I'm 99% sure float64 would work here as well looking at the error.

https://github.com/aws/aws-lambda-go/blob/de51f6811a68226f2238b77fd74b84df29c446f4/events/codepipeline_cloudwatch.go#L100C1-L109C2

L108's Version type as string

I don't personally reference this value in any of my code, the change was purely to get unmarshalling to not panic, so I'm not sure if there's going to be any breaking changes for users to utilise the value.

@bmoffatt
Copy link
Collaborator

I don't personally reference this value in any of my code, the change was purely to get unmarshalling to not panic,

If you haven't already, you can unblock yourself by copying the structs into your project, and deleting the fields in your copy.

I'm still following up with the service team to try and figure out what happened here.

@bmoffatt
Copy link
Collaborator

bmoffatt commented Jun 5, 2024

The service team identified errors in the sample event documentation which I believe lead to the type mismatches in the original PR that introduced this struct. Documentation should be fixed by now, and guidance from the service team confirmed that correct typing would be:

    .version -> string
    .detail.version -> numeric
    .detail.type.version -> string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug type/events issue or feature request related to the events package
Projects
None yet
Development

No branches or pull requests

2 participants