{"id":15639269,"url":"https://github.com/mtojek/aws-lambda-go-proxy","last_synced_at":"2025-04-30T07:05:37.272Z","repository":{"id":104722749,"uuid":"118339343","full_name":"mtojek/aws-lambda-go-proxy","owner":"mtojek","description":":zap: :cloud: Pass Lambda events to the application running on your machine | Debug real traffic locally | Forget about redeployments","archived":false,"fork":false,"pushed_at":"2018-01-21T17:50:29.000Z","size":27,"stargazers_count":87,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T07:05:28.851Z","etag":null,"topics":["aws","golang","lambda","proxy"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtojek.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T13:55:21.000Z","updated_at":"2023-08-15T22:04:08.000Z","dependencies_parsed_at":"2024-06-20T11:14:29.656Z","dependency_job_id":null,"html_url":"https://github.com/mtojek/aws-lambda-go-proxy","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/mtojek%2Faws-lambda-go-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtojek%2Faws-lambda-go-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtojek%2Faws-lambda-go-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtojek%2Faws-lambda-go-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtojek","download_url":"https://codeload.github.com/mtojek/aws-lambda-go-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251658200,"owners_count":21622819,"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","golang","lambda","proxy"],"created_at":"2024-10-03T11:25:12.935Z","updated_at":"2025-04-30T07:05:37.251Z","avatar_url":"https://github.com/mtojek.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aws-lambda-go-proxy\n\n[![Build Status](https://travis-ci.org/mtojek/aws-lambda-go-proxy.svg?branch=master)](https://travis-ci.org/mtojek/aws-lambda-go-proxy)\n\nStatus: **Done**\n\n![Gopher and Lambda](https://cdn-images-1.medium.com/max/400/1*SncdHqDPypbypdx2QmP6iQ.jpeg)\n\n*Source: medium.com*\n\n\nBriefly, run **Lambda** Go function on your machine and forget about redeployments!\n\nRun **proxy application** as Lambda function and **route all events** (TCP traffic) to a different, **even local** Go application. Forget about long hours of blindly debugging the function code, docker images and SAM models. Pass all **incoming, real Lambda requests** to the Go application that you're **currently developing**.\n\nNo need to prepare *Test events* or wrap *http.Request* magically. \n\n## Quickstart\n\n*In this case I will show you how to process requests sent to API Gateway.*\n\nBuild **aws-lambda-go-proxy** package:\n\n```bash\n$ go get github.com/mtojek/aws-lambda-go-proxy\n```\n\nGo to the source directory and run *make* to create a deployment artifact:\n\n```bash\n$ make\ngo get -v ./...\nGOOS=linux go build -o main\nzip deployment.zip main\nupdating: main (deflated 65%)\nrm main\n```\n\nIn the mean time, let's build and run a sample Go application (for educational reasons) - [Hello World](https://github.com/aws-samples/lambda-go-samples/blob/master/main.go):\n\n```bash\n$ go get github.com/aws-samples/lambda-go-samples\n$ _LAMBDA_SERVER_PORT=9999 lambda-go-samples\n```\n\nThis will expose the *lambda-go-samples* behind the port 9999 (TCP). If you're curious about this sample, feel free to read the [blog post](https://aws.amazon.com/blogs/compute/announcing-go-support-for-aws-lambda/).\n\nNow, it's time to deploy **aws-lambda-go-proxy** on AWS Lambda. I hope you can figure this out on your own (if not, please read first the mentioned blog post). Few hints:\n\n* *deployment.zip* will be created if you run *make* command, it contains the binary of *aws-lambda-go-proxy*\n* set *LAMBDA_DEBUG_PROXY* environment variable to the remote address of the target application, e.g.: *0.tcp.ngrok.io:12345*\n* configure *API Gateway* trigger (API name: *lambda-go*, Deployment stage: *prod*, Security: *open* remember, this is not secure and only for educational reasons)\n\nAs you may see I set the *LAMBDA_DEBUG_PROXY* variable to *ngrok* address. It is due a NAT that's in front of me. With [ngrok](https://ngrok.com/) you can open a direct network tunnel to a specified exposed local port:\n\n```bash\n$ ngrok tcp 9999\n```\n\nHere you can find more details regarding [TCP tunnels](https://ngrok.com/docs#tcp) in ngrok.\n\nOnce you have API Gateway API deployed and you a URL similar to the following:\n\nhttps://hefunef32.execute-api.us-west-2.amazonaws.com/prod/main\n\nFeel free to execute *curl* command:\n\n```bash\n$ curl -XPOST -d \"horse\" \"https://hefunef32.execute-api.us-west-2.amazonaws.com/prod/main\"\nHello horse\n```\n\nEaster Egg: https://twitter.com/bbctwo/status/549296800709234688 :)\n\n*Notice: It may be necessary to hit curl few times to let Lambda establish a connection with your machine. Internal server error should appear.*\n\nYou should also notice some log entries appearing in your local console:\n\n```bash\n2018/01/21 04:12:01 Processing Lambda request ae976f75-e0af-478c-ad06-3d460fe1881d\n2018/01/21 04:12:05 Processing Lambda request be6fd715-5cfd-4ee7-8f67-2a20c0a98af2\n2018/01/21 04:14:14 Processing Lambda request a7288c78-596e-4772-a4c4-2d1dc9622410\n```\n\n## Behind the scenes\n\n**aws-lambda-go-proxy** runs a TCP proxy to the target host defined via environment variable *LAMBDA_DEBUG_PROXY*. Whole Lambda traffic is passed to that address, what actually allows for processing Lambda events on a different machine, e.g. a developer host (debugging reasons).\n\nAs the Lambda Go runtime uses *net/rpc* internals to communicate, you can preview whole communication with *tcpdump*. Here are some sniffs:\n\n```bash\nInvokeRequest........Payload..........\nClientContext.tId.....XAmznTraceId.....Deadline......InvokedFunctionArn.....CognitoIdentityId.....CognitoIdentityPoolId....\n...;......InvokeRequest_Timestamp........Seconds.....Nanos.......[......{\"resource\":\"/main\",\"path\":\"/main\",\"httpMethod\":\"POST\",\"headers\":{\"Accept\":\"*/*\",\"CloudFront-Forwarded-Proto\":\"https\",\"CloudFront-Is-Desktop-Viewer\":\"true\",\"CloudFront-Is-Mobile-Viewer\":\"false\",\"CloudFront-Is-SmartTV-Viewer\":\"false\",\"CloudFront-Is-Tablet-Viewer\":\"false\",\"CloudFront-Viewer-Country\":\"PL\",\"Content-Type\":\"application/x-www-form-urlencoded\",\"Host\":\"\u003credacted\u003e.execute-api.us-west-2.amazonaws.com\",\"User-Agent\":\"curl/7.30.0\",\"Via\":\"1.1 \u003credacted\u003e.cloudfront.net (CloudFront)\",\"X-Amz-Cf-Id\":\"\u003credacted\u003e\",\"X-Amzn-Trace-Id\":\"\u003credacted\u003e\",\"X-Forwarded-For\":\"\u003credacted\u003e\",\"X-Forwarded-Port\":\"443\",\"X-Forwarded-Proto\":\"https\"},\"queryStringParameters\":null,\"pathParameters\":null,\"stageVariables\":null,\"requestContext\":{\"requestTime\":\"\u003credacted\u003e\",\"path\":\"/prod/main\",\"accountId\":\"\u003credacted\u003e\",\"protocol\":\"HTTP/1.1\",\"resourceId\":\"\u003credacted\u003e\",\"stage\":\"prod\",\"requestTimeEpoch\":\u003credacted\u003e,\"requestId\":\"\u003credacted\u003e\",\"identity\":{\"cognitoIdentityPoolId\":null,\"accountId\":null,\"cognitoIdentityId\":null,\"caller\":null,\"sourceIp\":\"\u003credacted\u003e\",\"accessKey\":null,\"cognitoAuthenticationType\":null,\"cognitoAuthenticationProvider\":null,\"userArn\":null,\"userAgent\":\"curl/7.30.0\",\"user\":null},\"resourcePath\":\"/main\",\"httpMethod\":\"POST\",\"apiId\":\"\u003credacted\u003e\"},\"body\":\"horse\",\"isBase64Encoded\":false}.$\u003credacted\u003e.JRoot=\u003credacted\u003e;Sampled=0.....@\u003e..?]....3arn:aws:lambda:us-west-2:\u003credacted\u003e:function:main.\n```\n\n```bash\nE.....@.@...........'...-\\h...!...\"..{.....\nJ.|.J.|......Function.Invoke...;...6{\"statusCode\":200,\"headers\":null,\"body\":\"Hello horse\"}\n```\n\n## Disclaimer\n\nThe idea of passing TCP traffic to remotely running applications has been described and used to simplify debugging process of Go Lambda functions to prevent redeployments. I hope it will attract more users to [AWS Lambda](https://aws.amazon.com/lambda/) based solutions, including Github community.\n\n## License\n\nSee [LICENSE](LICENSE) for the details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtojek%2Faws-lambda-go-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtojek%2Faws-lambda-go-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtojek%2Faws-lambda-go-proxy/lists"}