{"id":22138250,"url":"https://github.com/z0mbix/vagrant-ec2-imposter","last_synced_at":"2025-03-24T10:26:18.672Z","repository":{"id":139776718,"uuid":"96580668","full_name":"z0mbix/vagrant-ec2-imposter","owner":"z0mbix","description":"A vagrant VM to simulate some parts of an EC2 instance","archived":false,"fork":false,"pushed_at":"2017-08-23T22:12:45.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T15:50:43.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/z0mbix.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":"2017-07-07T22:20:29.000Z","updated_at":"2020-03-24T08:34:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"81a12e09-ed09-4b41-b79b-dbf70ea3c9ce","html_url":"https://github.com/z0mbix/vagrant-ec2-imposter","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/z0mbix%2Fvagrant-ec2-imposter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z0mbix%2Fvagrant-ec2-imposter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z0mbix%2Fvagrant-ec2-imposter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z0mbix%2Fvagrant-ec2-imposter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z0mbix","download_url":"https://codeload.github.com/z0mbix/vagrant-ec2-imposter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245251103,"owners_count":20584828,"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":[],"created_at":"2024-12-01T20:09:12.902Z","updated_at":"2025-03-24T10:26:18.648Z","avatar_url":"https://github.com/z0mbix.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EC2 Wannabe\n\n## Descrtiption\n\nThis vagrant VM is an attempt to emulate some aspects of an EC2 instance, including user-data and some parts of the metadata service.\n\n## Requirements\n\n* [Vagrant](https://www.vagrantup.com/)\n* [VirtualBox](https://www.virtualbox.org/)\n\n## Setup\n\nChoose your Linux distro in `Vagrantfile` by setting these two variables:\n\n```\nuserdata_file = 'user-data.centos'\nbox = 'centos/7'\n```\n\nor\n\n```\nuserdata_file = 'user-data.ubuntu'\nbox = 'ubuntu/xenial64'\n```\n\nI've only tested with these two, but it may work on other systemd based distributions if you set these variables appropriately. If it doesn't, please send me a pull request.\n\n## Usage\n\nStart the VM:\n\n```\nvagrant up\n```\n\nThis should provision the VM using the user data script you specified above.\n\nLogin:\n\n```\nvagrant ssh\n```\n\n## AWS Credentials\n\nIf you set the following environment variables correctly on your host, your VM should be able to use these by way of the `iam/security-credentials/{role}` metadata endpoint:\n\n```\nexport AWS_DEFAULT_REGION=\nexport AWS_ACCESS_KEY_ID=\nexport AWS_SECRET_ACCESS_KEY=\n```\n\nThese get copied in to the VM so the metadata service can use them. Once the service is running you can use `awscli` and the AWS SDK as if on a real instance.\n\nI use [direnv](https://direnv.net/) to handle this, but as long as the environment variables exist, you should be OK.\n\n## Metadata Service\n\nYou can use some of the basic metadata endpoints, e.g.:\n\n```\n$ curl http://169.254.169.254/latest/meta-data/local-hostname\nip-10-0-2-15.eu-west-1.compute.internal\n```\n\n```\n$ curl http://169.254.169.254/latest/meta-data/local-ipv4\n10.0.2.15\n```\n\n```\n$ curl http://169.254.169.254/latest/user-data\n#!/usr/bin/env bash\n\nyum install -y epel-release\nyum install -y python-pip\n\npip install --upgrade pip\npip install awscli\npip install boto\npip install boto3\n```\n\n```\n$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/iam_role\n{\n  \"AccessKeyId\": \"AAAAAAAAAAAAAAAAAAAA\",\n  \"Code\": \"Success\",\n  \"Expiration\": \"2017-07-08T15:31:58Z\",\n  \"LastUpdated\": \"2017-07-07T15:31:58Z\",\n  \"SecretAccessKey\": \"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\",\n  \"Token\": \"\",\n  \"Type\": \"AWS-HMAC\"\n}\n```\n\n```\n$ curl http://169.254.169.254/latest/dynamic/instance-identity/document\n{\n  \"accountId\": \"123456789012\",\n  \"architecture\": \"x86_64\",\n  \"availabilityZone\": \"eu-west-1a\",\n  \"billingProducts\": null,\n  \"devpayProductCodes\": null,\n  \"imageId\": \"ami-12abcd34\",\n  \"instanceId\": \"i-0ec73af280cfd347b\",\n  \"instanceType\": \"t2.medium\",\n  \"kernelId\": null,\n  \"pendingTime\": \"2017-07-10T09:01:20Z\",\n  \"privateIp\": \"10.0.2.15\",\n  \"ramdiskId\": null,\n  \"region\": \"eu-west-1\",\n  \"version\": \"2010-08-31\"\n}\n```\n\n## Proxy Support\n\nIf you are behind a proxy, this should work if you install the `vagrant-proxyconf` plugin:\n\n```\n$ vagrant plugin install vagrant-proxyconf\n```\n\nand export the usual environment variables:\n\n```\nHTTPS_PROXY=http://myproxy.internal.foo:3128\nHTTP_PROXY=http://myproxy.internal.foo:3128\nNO_PROXY=localhost,127.0.0.1,.internal.foo\nhttp_proxy=http://myproxy.internal.foo:3128\nhttps_proxy=http://myproxy.internal.foo:3128\nno_proxy=localhost,127.0.0.1,.internal.foo\n```\n\n## Tests\n\nIf you want to add a new distro, you can use the inspec tests to validate everything works.\n\nRun the inspec tests from your host:\n\n```\n$ inspec exec --sudo -t ssh://vagrant@127.0.0.1:$(vagrant ssh-config | grep Port |awk '{print $2}') test/default.rb -i .vagrant/machines/default/virtualbox/private_key\n\nProfile: tests from test/default.rb\nVersion: (not specified)\nTarget:  ssh://vagrant@127.0.0.1:2200\n\n\n  File /etc/default/aws\n     ✔  mode should cmp == \"0644\"\n     ✔  owner should cmp == \"root\"\n     ✔  group should cmp == \"root\"\n  Parse Config\n     ✔  File /etc/default/aws content should match /AWS_DEFAULT_REGION=.+/\n     ✔  File /etc/default/aws content should match /AWS_ACCESS_KEY_ID=.+/\n     ✔  File /etc/default/aws content should match /AWS_SECRET_ACCESS_KEY=.+/\n  File /etc/systemd/system/metadata.service\n     ✔  mode should cmp == \"0644\"\n     ✔  owner should cmp == \"root\"\n     ✔  group should cmp == \"root\"\n  Service metadata\n     ✔  should be installed\n     ✔  should be enabled\n     ✔  should be running\n  Port 5000\n     ✔  should be listening\n     ✔  addresses should include \"127.0.0.1\"\n     ✔  protocols should eq [\"tcp\"]\n     ✔  processes should include \"python\"\n  File /etc/user-data\n     ✔  mode should cmp == \"0755\"\n  Command hostname\n     ✔  stdout should eq \"ip-10-0-2-15.eu-west-1.compute.internal\\n\"\n  Host ip-10-0-2-15.eu-west-1.compute.internal\n     ✔  should be resolvable\n  Command curl\n     ✔  http://169.254.169.254/latest/meta-data/local-hostname stdout should eq \"ip-10-0-2-15.eu-west-1.compute.internal\"\n  Command curl\n     ✔  http://169.254.169.254/latest/meta-data/local-ipv4 stdout should eq \"10.0.2.15\"\n\nTest Summary: 21 successful, 0 failures, 0 skipped\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz0mbix%2Fvagrant-ec2-imposter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz0mbix%2Fvagrant-ec2-imposter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz0mbix%2Fvagrant-ec2-imposter/lists"}