Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Labs

Sending SMS Text via Cloud Functions

Cloud Functions are, in a way, the glue between services. These services are often other ones on Google Cloud – but they don’t have to be. This hands-on lab will explore integrating Cloud Functions with one of them: Twilio, a web service API for SMS, voice, and other communications. With the help of this external service, we will set up a Cloud Function that, when triggered by the upload of an object to a Cloud Storage bucket, sends a text that alerts one or more recipients of the action taken — complete with details about the object. Note: Because of the Twilio limitations, this lab will only work with telephone numbers from the U.S. and Canada.

Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Jun 14, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Enable necessary APIs and services.

    1. From the main Google Cloud console navigation, choose APIs & Services > Library.
    2. Search for Cloud Functions API, and enable the service, if necessary.
    3. From the Library page, search for Cloud Build API and enable the service, if necessary.
  2. Challenge

    Create the required bucket.

    1. From the main navigation, go to Storage > Browser.
    2. Choose Create bucket.
    3. In the Name field, enter a unique name for the bucket to hold the incoming image and click Continue.
    4. From the Choose where to store your data options, choose Region and select us-east1 as the region.
    5. Leave the remaining values at their defaults, and click Create.
  3. Challenge

    Retrieve files from repo and configure.

    1. Activate the Cloud Shell.

    2. From the Cloud Shell, issue the following command to clone the repository for this course:

      git clone https://github.com/linuxacademy/content-gc-functions-deepdive
      
    3. Change directory to the lab folder: cd content-gc-functions-deepdive/cloud-functions-sms-lab

    4. Open Shell Editor by clicking the pencil icon.

    5. Navigate to the cloud-functions-sms-lab folder, and open the two files there.

    6. In the main.py file, make the necessary updates to the variables starting on line 7:

      • TWILIO_ACCOUNT_SID = "[YOUR_TWILIO_ACCOUNT_SID]"
      • TWILIO_AUTH_TOKEN = "[YOUR_TWILIO_AUTH_TOKEN]"
      • TWILIO_NUMBER = "[YOUR_TWILIO_NUMBER]"
      • TO_NUMBERS = ['ARRAY_OF_NUMBERS']
      • BUCKET = "[BUCKET_NAME]"
    7. Save the file.

  4. Challenge

    Create Cloud Function.

    1. Navigate to the Cloud Functions dashboard.
    2. Click Create function.
    3. Apply the following settings:
      • Name: acg-sms-function
      • Trigger: Cloud Storage
      • Bucket: Your bucket name
    4. Click Save and then Next.
      • Runtime: Python 3.9
      • Source code: Inline editor
    5. From the Cloud Shell Editor, select all of the main.py code and copy it.
    6. In the main.py field of the function, paste the copied code.
    7. From the Cloud Shell Editor, open requirements.txt, and copy all.
    8. In the requirements.txt field of the function, paste the copied code.
    9. In the Entry Point field, enter send_sms.
    10. Click Deploy.
  5. Challenge

    Test in Cloud Shell and Cloud Storage.

    1. In the Cloud Shell, issue the following commands:
    cd images
    ls
    gsutil cp a-cloud-guru.png gs://<BUCKET_NAME>
    
    1. Check your phone for an incoming text message.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans