{"id":20697425,"url":"https://github.com/epomatti/aws-ec2-swap","last_synced_at":"2026-04-27T03:32:28.718Z","repository":{"id":221421559,"uuid":"754139827","full_name":"epomatti/aws-ec2-swap","owner":"epomatti","description":"Memory swap on EC2 with Ubuntu","archived":false,"fork":false,"pushed_at":"2024-02-09T12:59:58.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T15:11:07.760Z","etag":null,"topics":["aws","ec2","swap","terraform","ubuntu"],"latest_commit_sha":null,"homepage":"","language":"HCL","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/epomatti.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":"2024-02-07T13:32:18.000Z","updated_at":"2024-02-07T20:02:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"b7bc1a62-d159-413c-aa73-7d9b8ae1eca0","html_url":"https://github.com/epomatti/aws-ec2-swap","commit_stats":null,"previous_names":["epomatti/aws-ec2-swap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/epomatti/aws-ec2-swap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ec2-swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ec2-swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ec2-swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ec2-swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epomatti","download_url":"https://codeload.github.com/epomatti/aws-ec2-swap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ec2-swap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32321472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","ec2","swap","terraform","ubuntu"],"created_at":"2024-11-17T00:18:01.572Z","updated_at":"2026-04-27T03:32:28.688Z","avatar_url":"https://github.com/epomatti.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS EC2 memory swap\n\nSwap commands are scripted in the `userdata` file following instructions from this [article][1].\n\nCreate the `.auto.tfvars` file:\n\n```terraform\naws_region    = \"us-east-2\"\nami           = \"ami-045909c05cb423e93\" # Ubuntu 22.04 arm64\ninstance_type = \"t4g.nano\"\n```\n\nCreate the infrastructure:\n\n```sh\nterraform init\nterraform apply -auto-approve\n```\n\nVerify that the swap is working, such as by using SSM Patch.\n\n```sh\nfree -h\nlsblk\n```\n\nAlong with the swap file or partition, swapiness might also need to be configured:\n\n```sh\n### Swap ###\nswapiness=20\nsysctl -w vm.swappiness=$swapiness\necho \"vm.swappiness=$swapiness\" \u003e\u003e /etc/sysctl.conf\n\n# swap\nswapfile=\"/swapfile\"\ndd if=/dev/zero of=$swapfile bs=64M count=8\nchmod 600 $swapfile\nmkswap $swapfile\nswapon $swapfile\necho \"$swapfile swap swap defaults 0 0\" \u003e\u003e /etc/fstab\n```\n\nTo check the swapiness:\n\n```sh\ncat /proc/sys/vm/swappiness\n```\n\n## Command reference\n\n```sh\n# Confirm you can use swap\nlsblk -f\n\n# Determine the amount of space needed\n# If under 1GB RAM, use an equal amount. If more than 1GB RAM, use square root at a minimum\nfree -hm\n\n# swap file = block size (bs) * number of blocks (count)\ndd if=/dev/zero of=/swapfile bs=128M count=4\n\n# update the read and write permissions for the swap file\nchmod 600 /swapfile\n\n# set up a Linux swap area\nmkswap /swapfile\nswapon /swapfile\n\n# verify that the procedure was successful\nswapon -s\n\n# make the swap file usable by the kernel on the next reboot\necho '/swapfile swap swap defaults 0 0' \u003e\u003e /etc/fstab\n```\n\n## Sources\n\n```\nhttps://serverfault.com/questions/218750/why-dont-ec2-ubuntu-images-have-swap\nhttps://askubuntu.com/questions/103915/how-do-i-configure-swappiness\nhttps://askubuntu.com/questions/192304/changing-swappiness-in-sysctl-conf-doesnt-work-for-me\nhttps://unix.stackexchange.com/questions/23072/how-can-i-check-if-swap-is-active-from-the-command-line\n```\n\n---\n\n### Clean-up\n\n```sh\nterraform destroy -auto-approve\n```\n\n\n[1]: https://repost.aws/knowledge-center/ec2-memory-swap-file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepomatti%2Faws-ec2-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepomatti%2Faws-ec2-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepomatti%2Faws-ec2-swap/lists"}