我嘗試在產生的 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中文網其他相關文章!