{"id":24012861,"url":"https://github.com/glassechidna/lambdaeip","last_synced_at":"2025-04-15T08:37:54.239Z","repository":{"id":52306276,"uuid":"386132032","full_name":"glassechidna/lambdaeip","owner":"glassechidna","description":"Internet connectivity for your VPC-attached Lambda functions without a NAT Gateway","archived":false,"fork":false,"pushed_at":"2021-07-15T04:32:05.000Z","size":603,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-28T18:11:27.093Z","etag":null,"topics":["aws","aws-lambda"],"latest_commit_sha":null,"homepage":"","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/glassechidna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-15T02:03:42.000Z","updated_at":"2025-02-11T15:38:01.000Z","dependencies_parsed_at":"2022-09-06T08:40:34.829Z","dependency_job_id":null,"html_url":"https://github.com/glassechidna/lambdaeip","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassechidna%2Flambdaeip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassechidna%2Flambdaeip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassechidna%2Flambdaeip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassechidna%2Flambdaeip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glassechidna","download_url":"https://codeload.github.com/glassechidna/lambdaeip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038482,"owners_count":21202716,"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","aws-lambda"],"created_at":"2025-01-08T06:22:34.366Z","updated_at":"2025-04-15T08:37:54.221Z","avatar_url":"https://github.com/glassechidna.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lambdaeip\n\n## _Internet connectivity for your VPC-attached Lambda functions without a NAT Gateway_ \n\n### Background\n\nI occasionally have serverless applications that need to be attached to VPCs \n*and* have access to the Internet. The standard solution for that is to deploy\nNAT Gateways into each availability zone at a cost of $43/mo per zone. For that\nmoney I could have invoked my function 215 million times. \n\nToday I learned there's a ~better~ different way, courtesy of [Chaz Schlarp][tweet].\nI immediately went about generalising it so that I could set it and forget it in all\nmy personal environments.\n\n### Deployment\n\nYou have two options. The first is deploying the following CloudFormation template:\n\n```yaml\nTransform: AWS::Serverless-2016-10-31\n\nResources:\n  App:\n    Type: AWS::Serverless::Application\n    Properties:\n      Location:\n        ApplicationId: arn:aws:serverlessrepo:us-east-1:607481581596:applications/lambdaeip\n        SemanticVersion: 0.1.0\n      Parameters:\n        VpcId: vpc-abc123\n```\n\nThe second option is clicking [this link][console] to open the AWS web console,\nfill in the VPC ID and click the _Deploy_ button. It should look like the\nfollowing screenshot:\n\n![console screenshot](deploy.png)\n\n### How it works\n\nWhen a VPC-attached Lambda function is created, the Lambda service will\ncreate a network interface for it. This issues an EventBridge event, which\ntriggers `lambdaeip` to execute and associate an Elastic IP address with that\nENI. It releases the EIP when the Lambda function's ENI is deleted (e.g. if the\nfunction itself is deleted).\n\nThe way you identify whether a Lambda function should receive this special \ntreatment is by associating a \"sentinel\" security group with it. Here's\na complete example of how to do that:\n\n```yaml\nTransform: AWS::Serverless-2016-10-31\n\nParameters:\n  SubnetIds:\n    Type: List\u003cAWS::EC2::Subnet::Id\u003e\n\n  SentinelGroupId:\n    Type: AWS::SSM::Parameter::Value\u003cAWS::EC2::SecurityGroup::Id\u003e\n    Default: /lambdaeip/security-group-id\n\nResources:\n  Function:\n    Type: AWS::Serverless::Function\n    Properties:\n      Runtime: python3.8\n      Handler: index.handler\n      Timeout: 5\n      VpcConfig:\n        SecurityGroupIds: [!Ref SentinelGroupId, sg-whatever-else, sg-you-want]\n        SubnetIds: !Ref SubnetIds\n      InlineCode: |\n        import urllib.request\n\n        def handler(a, b):\n          content = urllib.request.urlopen(\"https://www.cloudflare.com/cdn-cgi/trace\").read()\n          print(content)\n```\n\n### Caveats\n\nChaz says not to use this in production, but YOLO if you care that much about\nsaving tens of dollars a month, it's probably not _really_ a production env, right?!\n\n[tweet]: https://twitter.com/schlarpc/status/1415393605330501632\n[console]: https://console.aws.amazon.com/lambda/home?region=us-east-1#/create/app?applicationId=arn:aws:serverlessrepo:us-east-1:607481581596:applications/lambdaeip\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassechidna%2Flambdaeip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglassechidna%2Flambdaeip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassechidna%2Flambdaeip/lists"}