I need to execute a bash script/command within a Google compute instance using Google Functions and get a response. AWS has an agent called SSM that let me do that with no hassle using Lambda, nevertheless I did not find anything like that on Google Cloud. On AWS using a nodejs lambda I use the following example:
ssm.sendCommand({
      DocumentName: documentName,
      InstanceIds: [ instanceId ],
      TimeoutSeconds: 3600,
      Parameters: { 
        'commands' : commands
      }
    }
How can I achieve what I want on Google Cloud? Thank you.
The nature of Google Cloud Functions is that it is the most abstract of the Serverless paradigms.  It assumes that all you are providing is stateless logic to be executed in one of the supported languages.  You aren't supposed to know nor care how that logic is executed.  Running bash (for example) makes an assumption that your Cloud Function is running in a Unix like environment where bash is available.  While this is likely to be a true statement, it isn't part of the "core" contract that you have with the Cloud Function environment.
An alternative solution I would suggest is to study Google's Cloud Run concept. Just like Cloud Functions, Cloud Run is serverless (you don't provision any servers and it scales to zero) but the distinction is that what is executed is a docker container. Within that container, your "code" within is executed in the container environment when called. Google spins up / spins down these containers as needed to satisfy your incoming load. Since it is running in a container, you have 100% control over what your logic does ... including running bash commands and providing any scripts or other environment needed to be able to run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With