{"id":19522229,"url":"https://github.com/captaincodeman/aws-block","last_synced_at":"2026-05-13T20:35:12.813Z","repository":{"id":66357870,"uuid":"88133277","full_name":"CaptainCodeman/aws-block","owner":"CaptainCodeman","description":"Middleware to block traffic coming from AWS networks","archived":false,"fork":false,"pushed_at":"2017-04-13T15:52:36.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T07:22:49.631Z","etag":null,"topics":["aws","aws-ec2","block","bots","golang","middleware"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CaptainCodeman.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-04-13T06:38:43.000Z","updated_at":"2017-10-30T07:15:29.000Z","dependencies_parsed_at":"2023-02-23T04:45:27.262Z","dependency_job_id":null,"html_url":"https://github.com/CaptainCodeman/aws-block","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CaptainCodeman/aws-block","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Faws-block","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Faws-block/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Faws-block/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Faws-block/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptainCodeman","download_url":"https://codeload.github.com/CaptainCodeman/aws-block/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Faws-block/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32999516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-ec2","block","bots","golang","middleware"],"created_at":"2024-11-11T00:37:51.162Z","updated_at":"2026-05-13T20:35:12.796Z","avatar_url":"https://github.com/CaptainCodeman.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Block\n\nMiddleware to block traffic coming from AWS networks by checking the various\n[AWS address ranges](http://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html).\n\nSorry AWS, but all the annoying bots usually seem to come from you ...\n\nIf you have a web site then you will likely have it visited by bots, oh so many bots.\nSome of them are useful and necessary and abide by `robots.txt` but many are badly bahaved\ncontent scrapers, abusing your bandwidth, overloading your servers and costing you money\nall so they can selling your content or use it to sell their own SEO services.\n\nAmazon EC2 seems to be the go-to solution for anyone wanting to host a web crawler.\nThis package makes it easy to block this server-to-server traffic in order to prioritize\ntraffic from legitimate site visitors.\n\n## Usage\n\nGet package and import it:\n\n    go get -u github.com/captaincodeman/aws-block\n\n```go\nimport (\n    \"net/http\"\n    \"golang.org/x/net/context\"\n    \"github.com/captaincodeman/aws-block\"\n)\n```\n\nCreate a new blocker instance configured as required:\n\n```go\nblocker := awsblock.New(\u0026awsblock.Config{\n    Interval: time.Hour * 24,   // periodic check for IP range updates\n    Region:   \"us-east-1\",      // region to block (empty for all)\n    Service:  \"ec2\",            // service to block (empty for all)\n})\n```\n\nStart the updating service, pass in a cancellable-context if cancellation is required\n(or else just use `context.Background()`):\n\n```go\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n\nblocker.Start(ctx, http.DefaultClient)\n```\n\nUse the blocker middleware to block any traffic coming from AWS:\n\n```go\nm := http.NewServeMux()\nm.HandleFunc(\"/\", index)\nh := blocker.Middleware(m)\n\nlog.Fatal(http.ListenAndServe(\":8080\", h))\n```\n\nOr use the `AWSRequest` method within your own middleware:\n\n```go\nfunc LogAWS(blocker *awsblock.Blocker, next http.Handler) http.Handler {\n\tfn := func(w http.ResponseWriter, r *http.Request) {\n\t\tif blocker.AWSRequest(r) {\n\t\t\tlog.Println(\"AWS request by\", r.UserAgent())\n\t\t}\n\n\t\tnext.ServeHTTP(w, r)\n\t}\n\n\treturn http.HandlerFunc(fn)\n}\n```\n\nIt's a good idea to start by logging the requests that match so that you can\nsee which traffic _would_ be blocked if the middleware was used. If you have\nsome valid / legitimate traffic coming from AWS you may want to create some\nwhitelisting system first (e.g. by useragent, hostname or IP) to allow it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincodeman%2Faws-block","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptaincodeman%2Faws-block","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincodeman%2Faws-block/lists"}