Deploy a Compute Instance with a Remote Startup Script

In this article, we will go through the lab Deploy a Compute Instance with a Remote Startup Script.

The challenge contains 4 required tasks

1.Create a storage bucket for startup scripts.

2.Create a virtual machine that runs a startup script from Cloud Storage.

3.Configure HTTP access for the virtual machine.

4.Deploy an application on an instance.

What is startup Script in GCP?

A startup script is a file that contains commands that run when a virtual machine (VM) instance boots. Compute Engine provides support for running startup scripts on Linux VMs and Windows VMs.

Challenge scenario

A basic bash script that installs the Apache webserver software called has been provided for you as a sample startup script. You can download this from the Student Resources links on the left side of the page.

Download Sample Startup Script

Upload the Startup Script to a Cloud Storage Bucket

  • Create a bucket with a unique bucket name.
  • Click on Create.
  • Upload the file to the bucket(Downloaded File).
  • Make the file publicly accessible.
  • Click on the three dots () icon at the right end of the filename.
  • Choose Edit permissions in the dropdown menu.
  • Add a new User, type allUsers to the name field, and choose Reader.
  • Click on the Save.
  • Click the filename and copy the URL, i.e. gs://.../ in Notepad for later use.

Configure Metadata in Creating VM instance

  • Create a new VM instance.
  • Select Allow HTTP traffic under the Firewall section.
  • Expand Management, security, disks, networking, sole tenancy.
  • In the Metadata section, add startup-script-url (Notepad) and paste the URL of the script file as the key-value.
  • Click on Create.

Inspect Instance Correctly Running Startup Script

  • Click the instance name to open its Details tab.
  • Expand the Logs and click Serial port 1 (console).
  • The startup script automatically installs the Apache webserver software while creating the VM instance.
  • Open the external IP in your web browser.
  • You should view the Apache default page if the startup script has been successfully executed.

Congratulations! Done with the challenge lab.



Thank you Stay Safe, Stay healthy.

If you found this helpful hit the clap button as much as you want.

Stay tuned till the next blog.

Google Developers Google Cloud Google News Lab

I am Google Cloud Certified Associate Cloud Engineer and MS Azure Certifed. I have been working on different fields including Cloud Computing , Sap ABAP.