{"id":18722430,"url":"https://github.com/nleiva/aws-testbed","last_synced_at":"2026-04-12T10:37:42.767Z","repository":{"id":87030947,"uuid":"379361568","full_name":"nleiva/aws-testbed","owner":"nleiva","description":"Create reproducible Linux environments in the cloud","archived":false,"fork":false,"pushed_at":"2021-09-17T17:30:22.000Z","size":945,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T04:04:21.926Z","etag":null,"topics":["ansible","aws","containerlab","docker","fedora","ubuntu"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/nleiva.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":"2021-06-22T18:12:30.000Z","updated_at":"2025-03-26T00:23:43.000Z","dependencies_parsed_at":"2023-05-30T07:15:15.026Z","dependency_job_id":null,"html_url":"https://github.com/nleiva/aws-testbed","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nleiva/aws-testbed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Faws-testbed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Faws-testbed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Faws-testbed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Faws-testbed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nleiva","download_url":"https://codeload.github.com/nleiva/aws-testbed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nleiva%2Faws-testbed/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31712292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T06:22:27.080Z","status":"ssl_error","status_checked_at":"2026-04-12T06:21:52.710Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["ansible","aws","containerlab","docker","fedora","ubuntu"],"created_at":"2024-11-07T13:41:23.867Z","updated_at":"2026-04-12T10:37:42.751Z","avatar_url":"https://github.com/nleiva.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Automating a testing environment setup on AWS\n\n[![Ansible Lint](https://github.com/nleiva/aws-testbed/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/nleiva/aws-testbed/actions/workflows/ansible-lint.yml)\n\nCloud resources are expensive, you only want to pay for them while your are using them. \nIf you only run tests or work on demos for a couple of hours per day, it makes a sense to shutdown all resources for the rest of the day to save on costs.\n\nIf you want to resume work or start fresh, your setup should ideally be re-created consistently and then destroyed with a single click of a button. \nThat's where automation comes in.\n\nA [Playbook](create-EC2-testbed.yml) example is included in this repository to illustrate how a Testbed environment can be automatically be provisioned for a particular use-case.\nIn this scenario, we create a virtual machine (VM) in AWS that is ready to run containerized multi-vendor network topologies. \nThe diagram below is a representation of the end-goal, that shows the AWS resources that need to be present otherwise created. \nIt also hints about Software requirements that will be installed, as well as providing pre-built network topology samples. \n\n\u003cp align=\"center\"\u003e\n\u003cimg height=\"400\" src=\"./pictures/aws.svg\"\u003e\n\u003c/p\u003e\n\nMore details -\u003e [How to consistently run temporary workloads on AWS and save money](https://nleiva.medium.com/how-you-can-consistently-run-temporary-workloads-in-the-cloud-37140b4b5e55)\n\n## Requirements\n\nAnsible 2.9+ needs to be [installed](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip) in your computer to run this example. [Python3](https://wiki.python.org/moin/BeginnersGuide/Download) as well.\n\n```bash\npython -m pip install --user ansible\n```\n\n### Python libraries\n\nAs we will interact with AWS, we need a couple of Python libraries to be present in the system.\n\n```bash\npip install --user -r requirements.txt\n```\n\n### Ansible Collections\n\nWe will also need the Ansible [Amazon AWS Collection](https://github.com/ansible-collections/amazon.aws#amazon-aws-collection).\n\n```bash\nansible-galaxy collection install -r collections/requirements.yml\n```\n\n## Creating the testbed\n\nFollow these steps to provision the testbed.\n\n1. Clone this repository: `git clone https://github.com/nleiva/aws-testbed.git`\n\n2. Make your [AWS account credentials](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`) available as environment variables (`export`).\n\n```bash\nexport AWS_ACCESS_KEY_ID='...'\nexport AWS_SECRET_ACCESS_KEY='...'\n```\n\n3. Run the [Playbook](create-EC2-testbed.yml) and wait a couple of minutes while a VM is provisioned and the software is installed:\n\n```bash\n ⇨  ansible-playbook create-EC2-testbed.yml -v\n\n\u003csnip\u003e\n\nTASK [Print out SSH access details] ***********************************************************************************************************************************************************\nok: [testbed-fedora34] =\u003e {\n    \"msg\": \"ssh -i testbed-private.pem fedora@ec2-54-175-179-XXX.compute-1.amazonaws.com\"\n}\n\nRUNNING HANDLER [configure_instance : Reboot machine] *****************************************************************************************************************************************\nchanged: [testbed-fedora34] =\u003e {\"changed\": true, \"elapsed\": 22, \"rebooted\": true}\n\nPLAY RECAP ************************************************************************************************************************************************************************************\nlocalhost                  : ok=25   changed=7    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   \ntestbed-fedora34           : ok=33   changed=22   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    \n```\n\nYou can now access the VM as displayed in the logs, for example: `ssh -i testbed-private.pem fedora@ec2-54-175-179-XXX.compute-1.amazonaws.com`.\n\n### Linux distribution\n\nYou can select either Fedora (34) or Ubuntu (20.04) by passing the variable `aws_distro` to the [Playbook](create-EC2-testbed.yml). By default it selects `fedora`.\n\nYou would run the [Playbook](create-EC2-testbed.yml) as follows, if you preferred to run an `ubuntu` machine. \n\n```bash\nansible-playbook create-EC2-testbed.yml -v --extra-vars \"aws_distro=ubuntu\"\n```\n\n### Instance type\n\nYou can select any instance type you prefer, based on your vCPU/Memory requirements, and price constrains. By default it selects `t2.micro`. Check out [On-Demand Plans for Amazon EC2](https://aws.amazon.com/ec2/pricing/on-demand/) for reference. Some examples:\n\nInstance name | On-Demand hourly rate | vCPU | Memory\n--- | --- | --- | ---\nt3.medium | $0.0416 | 2 | 4 GiB\nm5.large | $0.096 | 2 | 8 GiB\nt3.xlarge | $0.1664 | 4 | 16 GiB\nm4.xlarge | $0.2 | 4 | 16 GiB\nr5.xlarge | $0.252 | 4 | 32 GiB\nm5.2xlarge | $0.384 | 8 | 32 GiB\nr5.2xlarge | $0.504 | 8 | 64 GiB\nc5.metal | $4.08 | 96 | 192 GiB\n\nYou would run the [Playbook](create-EC2-testbed.yml) as follows, if you preferred to run a `m5.large` instance. \n\n```bash\nansible-playbook create-EC2-testbed.yml -v --extra-vars \"instance_type=m5.large\"\n```\n\nTo run the Containerlab's Firecracker micro-VMs [mode of operation](https://containerlab.srlinux.dev/manual/kinds/cvx/#mode-of-operation), you need nested virtualization support, which regular AWS instances don't provide ([Cloud Provider Instances with KVM support](https://ignite.readthedocs.io/en/stable/cloudprovider/)), so you would need to select a [bare metal instance type](https://aws.amazon.com/about-aws/whats-new/2018/05/announcing-general-availability-of-amazon-ec2-bare-metal-instances/). \n\nNote1: `a1.metal` is the cheapest bare metal instance. However, its architecture is `arm64`, not `x86_64` (it affect the image type you select).\n\nNote2: Rebooting a [bare metal instance](https://aws.amazon.com/about-aws/whats-new/2018/05/announcing-general-availability-of-amazon-ec2-bare-metal-instances/) takes considerably longer than a regular EC2 instance.\n\n### Volume type\n\nThe volume type is also configurable, check out [Amazon EBS pricing](https://aws.amazon.com/ebs/pricing/). The default is `gp2`.\n\nVolume Type | Price\n--- | ---\nGeneral Purpose SSD (gp3) - Storage\t| $0.08/GB-month\nGeneral Purpose SSD (gp2) Volumes | $0.10 per GB-month of provisioned storage\n\nTo select a different type, use the variable `volume_type`.\n\n```bash\nansible-playbook create-EC2-testbed.yml -v --extra-vars \"instance_type=m5.large volume_type=gp3\"\n```\n\n## Running a network topology\n\nOnce in the VM, you can run any of the examples of the [lab folder](lab) in the VM's `$HOME` directory. [Containerlab](https://github.com/srl-labs/containerlab) is already installed and does all the magic here. For example, a simple topology with two [FRR](https://frrouting.org/) routers connected back-to-back as described in [lab/frr](lab/frr/topology.yml) can be instantiated as follows:\n\n```bash\ncd lab/frr\nsudo clab deploy --topo topology.yml\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg height=\"250\" title=\"Network Topology\" src=\"pictures/topology.svg\"\u003e\u003cbr\u003e\n\u003c/p\u003e\n\nThe routers are [pre-configured](lab/frr/router1/frr.cfg) with a BGP session running between them. To access router1 for example:\n\n```bash\ndocker exec -it clab-mylab-router1 vtysh\n```\n\n[More details](lab/README.md) about Topology creation.\n\n## Deleting the test VM\n\nAs important as creating the VM, is being able to delete it. You can do this by running:\n\n```bash\nansible-playbook delete-EC2-testbed.yml -v\n```\n\nFor a specific Linux distribution:\n\n```bash\nansible-playbook delete-EC2-testbed.yml -v --extra-vars \"aws_distro=ubuntu\"\n```\n\n## Deleting all remaining AWS resources\n\nThis is optional. You can remove VPC, Subnet, Security Group, SSH Key Pair, and Internet Gateway, by setting the variable `delete` to `true` in the previous Playbook. For example:\n\n```bash\nansible-playbook delete-EC2-testbed.yml -v --extra-vars \"aws_distro=ubuntu delete=true\"\n```\n\nIf you used a non-default prefix, then:\n\n```bash\nansible-playbook delete-EC2-testbed.yml -v -e \"aws_prefix=another delete=true\"\n```\n\n## Alternative Ansible execution (optional)\n\n### Ansible Navigator\n\nYou can alternatively run it with Ansible Navigator:\n\n```bash\nansible-navigator run create-EC2-testbed.yml --ee false --penv AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY\n```\n\n### Run in Playbook in an Execution Environment\n\n#### Create Execution Environment image with Ansible builder\n\nImage details in [execution-environment.yml](execution-environment.yml). This is optional, you can pull the image from [quay.io/nleiva/aws_ee_image](https://quay.io/repository/nleiva/aws_ee_image). \n\n```bash\nansible-builder build -t aws_ee_image\n```\n\n#### Run Execution Environment\n\n```bash\nansible-navigator run create-EC2-testbed.yml --extra-vars \"instance_type=t3.medium\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnleiva%2Faws-testbed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnleiva%2Faws-testbed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnleiva%2Faws-testbed/lists"}