我尝试在生成的 AWS CodePipeline 模板中设置 UserParameters 配置,
Name: ... Actions: - Name: Invoke-Lambda ActionTypeId: Category: Invoke Owner: AWS Provider: Lambda Version: '1' Configuration: FunctionName: exampleLambdaFunction UserParameters: '{"example":"user-parameters"}'
在用 Go 编写的 AWS Lambda 上对其进行测试时,需要比平时更长的时间才能找到处理程序的函数定义,以解析将发送的 AWS CodePipeline JSON 事件,例如:
{ "CodePipeline.job": { "id": "11111111-abcd-1111-abcd-111111abcdef", "accountId": "111111111111", "data": { "actionConfiguration": { "configuration": { "FunctionName": "exampleLambdaFunction", "UserParameters": "{\"example\":\"user-parameters\"}" } }, "inputArtifacts": [ ... ], ... } } }
使用 github.com/aws/aws-lambda-go/events 包链接,其中包含 events.CodePipelineJobEvent,可帮助解组正在发送的 AWS CodePipeline JSON 事件
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) }
以上是在 Go 中解析从 AWS CodePipeline 发送到 AWS Lambda 的 UserParameters的详细内容。更多信息请关注PHP中文网其他相关文章!