{"library":"serverless-go-plugin","title":"Serverless Go Plugin","description":"This Serverless Framework plugin, currently at version 2.4.1, automates the compilation of Go functions for AWS Lambda deployments. It integrates directly with Serverless Framework commands like `deploy`, `deploy function`, and `invoke local`, compiling Go source code on the fly before packaging. Key differentiators include concurrent compilation across all CPU cores for efficiency, support for various Go runtimes including `go1.x` and `provided.al2` (with bootstrap), and features for monorepo-like project structures. The plugin manages handler path transformations and package exclusions/inclusions, simplifying the deployment workflow for Go-based serverless applications. Releases generally include minor feature enhancements, dependency updates, and bug fixes, maintaining an active development cadence. It specifically requires Serverless Framework version 1.52 or above to function.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install serverless-go-plugin"],"cli":null},"imports":["plugins:\n  - serverless-go-plugin","functions:\n  myGoFunc:\n    runtime: go1.x\n    handler: functions/myGoFunc/main.go","custom:\n  go:\n    binDir: .bin\n    cgo: 1\n    monorepo: true"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"{\n  \"name\": \"my-go-serverless-app\",\n  \"version\": \"1.0.0\",\n  \"description\": \"A serverless Go application with serverless-go-plugin\",\n  \"main\": \"handler.js\",\n  \"scripts\": {\n    \"deploy\": \"serverless deploy\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"serverless\": \"^3.0.0\",\n    \"serverless-go-plugin\": \"^2.0.0\",\n    \"@aws-cdk/aws-lambda\": \"^1.0.0\"\n  }\n}\n\n// serverless.yaml\nservice: my-go-app\n\nframeworkVersion: '3'\n\nprovider:\n  name: aws\n  runtime: go1.x # Default runtime, can be overridden per function\n  region: us-east-1\n  architecture: x86_64 # Default architecture\n\nplugins:\n  - serverless-go-plugin\n\ncustom:\n  go:\n    binDir: .bin # Target folder for compiled binaries\n    cmd: 'GOOS=linux go build -ldflags=\"-s -w\"' # Default compile command\n    supportedRuntimes: [\"go1.x\", \"provided.al2\"]\n\nfunctions:\n  hello:\n    handler: functions/hello/main.go # Path to the Go source file\n    events:\n      - httpApi:\n          path: /hello\n          method: get\n  greetArm:\n    runtime: provided.al2 # Example for a bootstrapped runtime\n    handler: functions/greet # Package path (assuming main.go inside)\n    architecture: arm64\n    environment:\n      MESSAGE: \"Hello from ARM64 Go Lambda!\"\n    events:\n      - httpApi:\n          path: /greet/{name}\n          method: get\n\n\n// functions/hello/main.go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/aws/aws-lambda-go/events\"\n\t\"github.com/aws/aws-lambda-go/lambda\"\n)\n\ntype Response events.APIGatewayProxyResponse\n\nfunc Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {\n\tbody := fmt.Sprintf(\"Hello from Go Lambda on x86_64! Path: %s\", request.Path)\n\tresp := Response{\n\t\tStatusCode:      200,\n\t\tIsBase64Encoded: false,\n\t\tBody:            body,\n\t\tHeaders: map[string]string{\n\t\t\t\"Content-Type\": \"application/json\"\n\t\t},\n\t}\n\treturn resp, nil\n}\n\nfunc main() {\n\tlambda.Start(Handler)\n}\n\n// functions/greet/main.go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/aws/aws-lambda-go/events\"\n\t\"github.com/aws/aws-lambda-go/lambda\"\n)\n\nfunc GreetHandler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {\n\tname := request.PathParameters[\"name\"]\n\tif name == \"\" {\n\t\tname = \"stranger\"\n\t}\n\tmessageEnv := os.Getenv(\"MESSAGE\")\n\tmessage := fmt.Sprintf(\"%s Greetings, %s!\", messageEnv, name)\n\n\treturn events.APIGatewayProxyResponse{\n\t\tStatusCode: http.StatusOK,\n\t\tHeaders:    map[string]string{\"Content-Type\": \"text/plain\"},\n\t\tBody:       message,\n\t},\n\tnil\n}\n\nfunc main() {\n\tlambda.Start(GreetHandler)\n}\n","lang":"typescript","description":"This quickstart demonstrates how to set up a Serverless project with `serverless-go-plugin` to deploy Go functions. It includes a `package.json` for dependencies, a `serverless.yaml` configured for both standard `go1.x` and `provided.al2` (ARM64) runtimes, and two example Go Lambda functions (`hello` and `greet`). The `greet` function illustrates using path parameters and environment variables.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}