Downloading files from Google Cloud Bucket onto Google Compuete Engine Instance Startup (.NET)

1k views Asked by At

I'm developing a .NET application which dynamically creates a Windows Virtual Machine instance intending to run software and data downloaded from a Google Cloud Storage Bucket.

Google's documentation states that software can be downloaded from a Google Cloud Bucket via a Windows's startup script also stored in a Google Cloud Bucket. (“Startup scripts can perform a number of actions, such as installing software, performing updates, turning on services, and any other tasks defined in the script.“ https://cloud.google.com/compute/docs/startupscript)

There is an example of how to get the Virtual Machine to access and run a startup script from a Google Cloud bucket, but I could not find an example or instructions on how to instruct that Virtual Machine startup script to go back to a Google Cloud Bucket and download the software and data for the Virtual Machine to execute.

My startup scripts has one line (below) attempting to copy the files from the Google Cloud Bucket to a local destination on the Virtual Machine:

ROBOCOPY "[GOOGLE CLOUD URL]/[GOOGLE_BUCKET_NAME]" "C:[DESTINATION_PATH_ON_VIRTUAL MACHINE]" /E /R:3 /W:5

The Virtual Machine serial output during initialization says the “syntax of the script is incorrect”. I can’t' tell if there is a problem with my script format, the ROBOCOPY function, or a problem accessing the Google Cloud Storage Bucket that contains the software and data?

Virtual Machine serial output snip: Starting ScriptManager startup script found in metadata. File type: url Successfully downloaded startup script https://console.developers.google.com/storage/browser/[GOOGLE_BUCKET_NAME]/MyWindowsStartupScript.cmd. Successfully wrote startup script to C:\Windows\TEMP\1701dd59-23ce-4040-a246-e061e672f138.cmd. windows-startup-script-cmd: The syntax of the command is incorrect. Finished running startup scripts.

Below summary of what works and where I'm stumped:

1) Create and launch a Virtual Machine instance that launches Windows. - WORKS

2) Virtual Machine can access the Windows startup script from Google Cloud Bucket - WORKS

3) Virtual Machine attempts to execute the downloaded script. - (Here the Virtal Machine says the "syntax of the script is incorrect ")

4) Next I WOULD LIKE to have the script instruct the Virtual Machine to get software and data to copy to the Virtual Machine and run the downloaded software to operate on the downloaded data. (I haven't gotten this far based on the problem in Step 3.)

All help on how to overcome this challenge is much appreciated. I value and respect the talent of the community!

1

There are 1 answers

0
Alexander Gaysinsky On

Reposting from:[email protected]

The problem you are encountering is that you are attempting to run a script that is invalid. According to the ROBOTCOPY documentation (https://technet.microsoft.com/en-us/library/cc733145.aspx) the first argument specifies the path to the source directory, not a script downloaded from the web. If you wish to download a file from within your running script, please refer to System.Net.WebClient documentation, or consider using the windows-startup-script-url metadata key.