Reputation: 1780
I set up a static External IP address for a Google Compute Engine VM Instance and when I SSH into the machine, my outbound requests (e.g. curl canhazip.com) originate from the static External IP, but when I launch the Google Cloud Shell from within the console or when I deploy an app (e.g. a Python app via gcloud app deploy, the IP address is different. Any ideas on how to make this consistent? Do I need to specify something in the app.yaml? In other words, if I wanted to deploy a Python app that looked like this:
import requests
print('requesting...')
res = requests.get("http://ip.jsontest.com/")
print(res.text)
How would I configure it to always return the same static External IP I already set up?
Upvotes: 1
Views: 675
Reputation: 9826
Both Cloud Shell as well as App Engine do not have direct network access.
For Cloud Shell, there are limitations to network access. Since Cloud Shell is an ephemeral instance, you do not have further control over things like IP addresses used.
App Engine Standard runs a sandboxed environment without network access. Applications have to use either the Sockets or URLFetch API to make external requests. The python runtime patches sockets and urllib so that most python code can use these APIs without further modification.
If you need a consistent source IP address for outgoing connections, you're likely looking for an egress NAT gateway. This setup will however also not be usable from Cloud Shell or App Engine Standard.
Upvotes: 1