Context
I was trying to setup the UserParameters
configuration within the AWS CodePipeline Template being generated,
Name: ...
Actions:
- Name: Invoke-Lambda
ActionTypeId:
Category: Invoke
Owner: AWS
Provider: Lambda
Version: '1'
Configuration:
FunctionName: exampleLambdaFunction
UserParameters: '{"example":"user-parameters"}'
While testing it out on an AWS Lambda, written in Go, it took a bit longer than usual to find out the Function Definition for the Handler, to parse the AWS CodePipeline JSON Event that would be sent, For Example:
{
"CodePipeline.job": {
"id": "11111111-abcd-1111-abcd-111111abcdef",
"accountId": "111111111111",
"data": {
"actionConfiguration": {
"configuration": {
"FunctionName": "exampleLambdaFunction",
"UserParameters": "{\"example\":\"user-parameters\"}"
}
},
"inputArtifacts": [
...
],
...
}
}
}
Solution
Use the github.com/aws/aws-lambda-go/events
package link which contains the events.CodePipelineJobEvent
that helps unmarshal the AWS CodePipeline JSON event being sent
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func Handler(ctx context.Context, event events.CodePipelineJobEvent) (string, error) {
fmt.Printf("received codepipeline event function name: %+v\n", event.CodePipelineJob.Data.ActionConfiguration.Configuration.FunctionName)
fmt.Printf("received codepipeline event user parameters: %+v\n", event.CodePipelineJob.Data.ActionConfiguration.Configuration.UserParameters)
return "cool", nil
}
func main() {
lambda.Start(Handler)
}
Top comments (0)