Package: expose-localhost
Platform SupportedRepo StatsDeploymentsExpose localhost using EC2Reverse proxy that creates a secure tunnel from public endpoint to locally running web serviceSetupEnvironment Variables:Environment variables can be loaded from any.envfile.PORT: Port number that has to be exposed (on which a localhostservice/app/apiis running)Optional envOPEN_PORT: Boolean flag to enableingressandegresson the specified port. Defaults toFalseCHANNEL_TIMEOUT: Timeout in seconds to wait for an incoming channel connection. Defaults to100IMAGE_ID: ID of any public AMI with an Ubuntu OS. Defaults to a region specific image ID.INSTANCE_TYPE: Instance type for tunneling. Defaults tot2.nanoAWS_ACCESS_KEY: Access key to access AWS resources. Defaults to~/.aws/configAWS_SECRET_KEY: Secret key to access AWS resources. Defaults to~/.aws/configAWS_REGION_NAME: Region name where the instance should live. Defaults toUS-WEST-2KEY_PAIR: Name for the ec2 key pair file. Defaults toexpose_localhostSECURITY_GROUP: Name for the security group to allow port access. Defaults toExpose LocalhostSERVER_INFO: Name for the JSON file to store the configuration info. Defaults toserver_info.jsonEMAIL_ADDRESS: Email address to create the self-signed SSL and private key. Defaults toUSER@expose-localhost.comORGANIZATION: Organization name for the certificate. Defaults to the AWS endpoint.HOSTED_ZONE: Hosted zone name registered usingroute53.Example:mywebsite.comSUBDOMAIN: Sub-domain that has to be added for the domain name.Example:tunnelLatencyCHANNEL_TIMEOUTcan be adjusted to improve latency depending on the application's role.Network LatencyShorter timeouts can make your server more responsive to incoming connections but may also lead to false negatives if network latency is high.
If connections take longer to establish due to network conditions, a short timeout might reject valid connections prematurely.Connection RateIf your server expects a high rate of incoming connections, and you want to process them quickly, a shorter timeout can be beneficial.
However, it also means that your server needs to be able to process connections rapidly.Resource UsageShort timeouts can lead to a higher rate of repeated checks, which may consume more CPU resources on the server.
Ensure that your server has the capacity to handle frequent connection checks, if you are settingCHANNEL_TIMEOUTtoo low.Custom endpointThe public DNS names for EC2 instances are long and messy. To avoid that, anArecord can be added to theroute53hosted zone.:warning:   Requires an active hosted zone onroute53.:bulb:SUBDOMAIN.HOSTED_ZONEwill be the endpoint to access the localhost from public internet.SSL certificateSecuring the tunnel requires the certificate chain and the key file.The certificate and key files should be inpemformat stored in current working directory.File names should be stored askey_fileandcert_fileenv var.No certs? No problem.exposewill generate a self-signed certificate and a private key automatically.:warning:   Some web browsers might throw a warning and some might even block a self-signed certificate/private CA.Manually generate self-signed certificateopenssl req -newkey rsa:2048 -sha256 -nodes -keyout private.pem -x509 -days 365 -out public.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=tunnel.example.com"To verify the generated certificateopenssl x509 -inform pem -in public.pem -noout -textUsageInstallationpython3-mpipinstallexpose-localhostTunneling:importosos.environ['env_file']='custom'# to load a custom .env fileimportexpose# Instantiate objecttunnel=expose.Tunnel()# Start tunnelingtunnel.start()# set 'purge' flag to 'True' to reclaim AWS resources if configuration fails# tunnel.start(purge=True)# Stop tunneling - deletes all AWS resources acquiredtunnel.stop()TroubleshootingIfE: Could not get lock /var/lib/dpkg/lock-frontendoccurs during startup, simply rerun the script with start command.This occurs whenapthasn't released the resources yet. A retry logic is in place to delete the lock file automatically.
However, if any such issues persist, re-runningtunnel.start()will simply re-configure the instance entirely.LimitationsCurrentlyexposecannot handle, tunneling multiple port numbers without modifying the following env vars in the.envfile.KEY_PAIR# SSH connection to AWS ec2KEY_FILE# Private key filename for self signed SSLCERT_FILE# Public certificate filename for self signed SSLSERVER_INFO# Filename to dump JSON data with server configuration informationSECURITY_GROUP# Ingress and egress firewall rules to control traffic allowed via VPCCoding StandardsDocstring format:GoogleStyling conventions:PEP 8Clean code with pre-commit hooks:flake8andisortRelease NotesRequirementpython-mpipinstallgitverseUsagegitverse-releasereverse-frelease_notes.rst-t'Release Notes'LintingPreCommitwill ensure linting, and the doc creation are run on every commit.Requirementpipinstallsphinx==5.1.1pre-commitrecommonmarkUsagepre-commitrun--all-filesPypi Packagehttps://pypi.org/project/expose-localhost/Runbookhttps://thevickypedia.github.io/expose/License & copyright© Vignesh RaoLicensed under theMIT License