{"id":20697487,"url":"https://github.com/epomatti/aws-ssh-tunneling","last_synced_at":"2026-04-21T11:35:49.747Z","repository":{"id":197695575,"uuid":"699113637","full_name":"epomatti/aws-ssh-tunneling","owner":"epomatti","description":"SSH tunneling example with AWS","archived":false,"fork":false,"pushed_at":"2023-10-02T01:15:14.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T18:36:24.337Z","etag":null,"topics":["aws","aws-security","aws-ssm","ec2","run-command","ssh","ssh-tunnel","ssh-tunneling","ssm","systems-manager","terraform"],"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}},"created_at":"2023-10-02T00:16:41.000Z","updated_at":"2023-10-02T01:16:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac1606f5-bf4a-4304-ab5f-fc63813dd4e0","html_url":"https://github.com/epomatti/aws-ssh-tunneling","commit_stats":null,"previous_names":["epomatti/aws-ssh-tunneling"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ssh-tunneling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ssh-tunneling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ssh-tunneling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epomatti%2Faws-ssh-tunneling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epomatti","download_url":"https://codeload.github.com/epomatti/aws-ssh-tunneling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242961747,"owners_count":20213315,"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-security","aws-ssm","ec2","run-command","ssh","ssh-tunnel","ssh-tunneling","ssm","systems-manager","terraform"],"created_at":"2024-11-17T00:18:16.701Z","updated_at":"2025-12-24T11:16:33.231Z","avatar_url":"https://github.com/epomatti.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS SSH Tunneling\n\nConnecting from a local workstation to AWS RDS MySQL via SSH tunneling.\n\n\u003cimg src=\".assets/ssh.png\" /\u003e\n\n\nCreate a `.auto.tfvars` to setup your stack:\n\n```terraform\naws_region         = \"us-east-2\"\nrds_instance_class = \"db.t4g.micro\"\nrds_multi_az       = false\nrds_username       = \"mysqladmin\"\nrds_password       = \"p4ssw0rd\"\n\njumpserver_allow_ssh = [\"0.0.0.0/0\"]\n```\n\nApply the stack:\n\n```sh\nterraform init\nterraform apply -auto-approve\n```\n\nCreate a temporary key pair:\n\n```sh\nmkdir keys\nssh-keygen -f keys/temp_key\n```\n\nAdd the public key to the `.ssh/authorized_keys` file using SSM Run Command:\n\n```sh\n# Set \"instance-id\" and \"SSH_PUB_KEY\" values accordingly\naws ssm send-command \\\n    --targets \"Key=InstanceIds,Values=instance-id\" \\\n    --document-name \"AWS-RunShellScript\" \\\n    --comment \"Add public key to SSH tunneling\" \\\n    --parameters \"commands='echo SSH_PUB_KEY \u003e\u003e /home/ubuntu/.ssh/authorized_keys'\" \\\n    --output text\n```\n\nCheck the command status:\n\n```sh\naws ssm get-command-invocation \\\n    --command-id \"ef7fdfd8-9b57-4151-a15c-db9a12345678\" \\\n    --instance-id \"i-1234567890abcdef0\" \\\n    --query Status\n```\n\nCheck if everything is working by connecting via SSH:\n\n```sh\nssh -i keys/temp_key ubuntu@\u003cINSTANCE_DNS\u003e\n```\n\nBefore creating the tunnel, enhance the security by allowing only your IP to connect via SSH:\n\n```terraform\njumpserver_allow_ssh = [\"YOUR PUBLIC IP/32\"]\n```\n\nApply the configuration.\n\nNow, create the tunnel:\n\n```\nssh -i keys/temp_key -f -N -l ubuntu -L 3306:RDS_MYSQL_FQDN:3306  EC2_INSTANCE_FQDN -v\n```\n\nIf the tunnel is created, you should now be able to connect to MySQL from your local machine on port `3306`.\n\n\n---\n\n### Clean-up\n\n```sh\nterraform destroy -auto-approve\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepomatti%2Faws-ssh-tunneling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepomatti%2Faws-ssh-tunneling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepomatti%2Faws-ssh-tunneling/lists"}