{"id":15187318,"url":"https://github.com/appleboy/gin-lambda","last_synced_at":"2025-10-27T05:30:58.750Z","repository":{"id":57693709,"uuid":"118200687","full_name":"appleboy/gin-lambda","owner":"appleboy","description":"running golang using gin framework in AWS Lambda \u0026 API Gateway","archived":false,"fork":false,"pushed_at":"2019-12-21T09:31:22.000Z","size":1269,"stargazers_count":68,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T06:58:17.371Z","etag":null,"topics":["aws-lambda","gin","golang","lambda"],"latest_commit_sha":null,"homepage":"https://github.com/gin-gonic/gin","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/appleboy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-20T02:22:12.000Z","updated_at":"2024-05-27T03:48:49.000Z","dependencies_parsed_at":"2022-09-26T21:01:14.663Z","dependency_job_id":null,"html_url":"https://github.com/appleboy/gin-lambda","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fgin-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fgin-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fgin-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appleboy%2Fgin-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appleboy","download_url":"https://codeload.github.com/appleboy/gin-lambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238437637,"owners_count":19472453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","gin","golang","lambda"],"created_at":"2024-09-27T18:20:17.663Z","updated_at":"2025-10-27T05:30:58.154Z","avatar_url":"https://github.com/appleboy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-lambda\n\n\u003cimg src=\"./images/logo.png\" /\u003e\n\nrunning golang using gin framework in AWS Lambda \u0026amp; API Gateway\n\n## Sample code\n\nsee the [main.go](./main.go) in master branch.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/apex/gateway\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc helloHandler(c *gin.Context) {\n\tname := c.Param(\"name\")\n\tc.String(http.StatusOK, \"Hello %s\", name)\n}\n\nfunc welcomeHandler(c *gin.Context) {\n\tc.String(http.StatusOK, \"Hello World from Go\")\n}\n\nfunc rootHandler(c *gin.Context) {\n\tc.JSON(http.StatusOK, gin.H{\n\t\t\"text\": \"Welcome to gin lambda server.\",\n\t})\n}\n\nfunc routerEngine() *gin.Engine {\n\t// set server mode\n\tgin.SetMode(gin.DebugMode)\n\n\tr := gin.New()\n\n\t// Global middleware\n\tr.Use(gin.Logger())\n\tr.Use(gin.Recovery())\n\n\tr.GET(\"/welcome\", welcomeHandler)\n\tr.GET(\"/user/:name\", helloHandler)\n\tr.GET(\"/\", rootHandler)\n\n\treturn r\n}\n\nfunc main() {\n\taddr := \":\" + os.Getenv(\"PORT\")\n\tlog.Fatal(gateway.ListenAndServe(addr, routerEngine()))\n}\n```\n\n## Build and Upload\n\nBuild binary\n\n```sh\n$ GOOS=linux go build -o main .\n$ zip deployment.zip main\n```\n\nUpload the `deployment.zip` to AWS Lambda using [drone-lambda](https://github.com/appleboy/drone-lambda) command.\n\n```\n$ AWS_ACCESS_KEY_ID=xxxx \\ \n  AWS_SECRET_ACCESS_KEY=xxx \\\n  drone-lambda --region ap-southeast-1 \\\n  --function-name function_name \\\n  --zip-file deployment.zip\n```\n\nOutput log:\n\n```json\n{\n  CodeSha256: \"r/I7yg9tX9MWPsPH337Xk5MIF1dVgkDCFhOrmAYe7hc=\",\n  CodeSize: 4334079,\n  Description: \"\",\n  Environment: {\n    Variables: {\n      PORT: \"8080\"\n    }\n  },\n  FunctionArn: \"arn:aws:lambda:ap-southeast-1:xxxxxxx:function:gin:7\",\n  FunctionName: \"gin\",\n  Handler: \"main\",\n  LastModified: \"2018-01-21T06:21:28.395+0000\",\n  MemorySize: 128,\n  Role: \"arn:aws:iam::xxxxxxx:role/service-role/test\",\n  Runtime: \"go1.x\",\n  Timeout: 3,\n  TracingConfig: {\n    Mode: \"PassThrough\"\n  },\n  Version: \"7\",\n  VpcConfig: {\n    SecurityGroupIds: [],\n    SubnetIds: []\n  }\n}\n```\n\n## AWS Policy\n\nAdd the following AWS policy if you want to integrate with CI/CD tools like Jenkins, GitLab Ci or Drone.\n\n```json\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"s3:PutObject\",\n        \"iam:ListRoles\",\n        \"lambda:UpdateFunctionCode\",\n        \"lambda:CreateFunction\"\n      ],\n      \"Resource\": \"*\"\n    }\n  ]\n}\n```\n\n## Benchmark\n\nMemory: 128 MB, Latencies: `6.091282008s`\n\n```\n$ vegeta attack -rate=1024 -duration=10s -targets=target2.txt | tee results.bin | vegeta report\nRequests      [total, rate]            10240, 1024.10\nDuration      [total, attack, wait]    20.335101947s, 9.999018014s, 10.336083933s\nLatencies     [mean, 50, 95, 99, max]  6.091282008s, 4.893951645s, 14.508009942s, 17.11847442s, 20.128384389s\nBytes In      [total, mean]            143360, 14.00\nBytes Out     [total, mean]            0, 0.00\nSuccess       [ratio]                  100.00%\nStatus Codes  [code:count]             200:10240\n```\n\nMemory: 512 MB, Latencies: `1.491340336s`\n\n```\n$ vegeta attack -rate=1024 -duration=10s -targets=target2.txt | tee results.bin | vegeta report\nRequests      [total, rate]            10240, 1024.10\nDuration      [total, attack, wait]    11.989730554s, 9.999012371s, 1.990718183s\nLatencies     [mean, 50, 95, 99, max]  1.491340336s, 1.114643849s, 4.112241113s, 6.087949237s, 10.107294516s\nBytes In      [total, mean]            143360, 14.00\nBytes Out     [total, mean]            0, 0.00\nSuccess       [ratio]                  100.00%\nStatus Codes  [code:count]             200:10240\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2Fgin-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappleboy%2Fgin-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappleboy%2Fgin-lambda/lists"}