dev-resources.site
for different kinds of informations.
Parse UserParameters sent from AWS CodePipeline to AWS Lambda in Go
Published at
10/2/2024
Categories
aws
go
awscodepipeline
awslambda
Author
prithvijj
Author
9 person written this
prithvijj
open
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)
}
References
awslambda Article's
30 articles in total
Build a Crypto Price Alert System with Telegram and AWS Lambda
read article
Leveraging Docker with AWS Lambda for Custom Runtimes and Large Deployments
read article
Docker for Serverless: Customizing Functions and Scaling Flexibly
read article
Inventory Management with AWS Lambda λ
read article
Lambda Power Tuning: Una comparativa entre arquitecturas x86_64 y arm64
read article
A Beginners Guide to Serverless API Gateway Authentication with Lambda Authorizer
read article
Serverless Functions: Unlocking the Power of AWS Lambda, Azure Functions, and More
read article
Mastering Serverless and Event-Driven Architectures with AWS: Innovations in Lambda, EventBridge, and Beyond
read article
Parse UserParameters sent from AWS CodePipeline to AWS Lambda in Go
currently reading
Leveraging Amazon Connect for Real-Time Incident Response Calls
read article
Lambda Code Execution Freeze/Thaw
read article
Efficiently Delete Inactive User Data Using TypeScript and AWS Lambda
read article
Unlocking Serverless: Build Your First Python AWS Lambda Function
read article
Lamba LLRT(Low Latency Runtime Javascript)
read article
Building Scalable Microservices with AWS Lambda and Serverless
read article
Serverless Architecture Best Practices
read article
Deep Dive on Writing and Reading Data to DynamoDB Table from Lambda Functions Using AWS Cloud Map Service Discovery
read article
AWS Lambda in Deno or Bun
read article
Lambda extension to cache SSM and Secrets Values for PHP Lambda on CDK
read article
Create a Fast Node.js Serverless Backend Using AWS Lambda and DynamoDB
read article
30-day Learning Challenge: Day 2— Learning AWS S3
read article
AWS Lambda Functions Failure Management
read article
Understanding Load Balancers: How They Work, Types, Algorithms, and Use Cases
read article
How to Deploy Dart Functions to AWS Lambda
read article
Using Custom Authorization - Request based for AWS Lambda
read article
How to generate a presigned url to upload images to S3
read article
Create an AppSync API using Terraform
read article
Creating a Cognito Trigger using CDK and TypeScript
read article
API Gateway REST API with Lambda Integration
read article
AWS Lambda Runtime debate
read article
Featured ones: