0
0
GCPcloud~10 mins

Pub/Sub with Cloud Functions integration in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Pub/Sub topic named 'my-topic'.

GCP
gcloud pubsub topics create [1]
Drag options to blanks, or click blank then click option'
Amy-topic
Btopic-1
Ccloud-topic
Dpubsub-topic
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different topic name than 'my-topic'.
Omitting the topic name.
2fill in blank
medium

Complete the code to deploy a Cloud Function named 'processMessage' triggered by the Pub/Sub topic 'my-topic'.

GCP
gcloud functions deploy processMessage --trigger-topic=[1] --runtime python312 --entry-point main
Drag options to blanks, or click blank then click option'
Atopic-1
Bmy-topic
Ccloud-topic
Dpubsub-topic
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different topic name in the trigger.
Omitting the trigger-topic flag.
3fill in blank
hard

Fix the error in the Cloud Function code to correctly decode the Pub/Sub message data.

GCP
def main(event, context):
    import base64
    message = base64.b64decode(event['data']).decode('utf-8')
    print('Received message:', [1])
Drag options to blanks, or click blank then click option'
Aevent['data']
Bmessage
Ccontext
Devent
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the raw event data instead of the decoded message.
Using the context object instead of the message.
4fill in blank
hard

Fill both blanks to create a subscription named 'my-subscription' for the topic 'my-topic'.

GCP
gcloud pubsub subscriptions create [1] --topic=[2]
Drag options to blanks, or click blank then click option'
Amy-subscription
Bmy-topic
Csubscription-1
Dtopic-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched subscription or topic names.
Omitting either the subscription name or topic flag.
5fill in blank
hard

Fill all three blanks to publish a message 'Hello, Cloud!' to the Pub/Sub topic 'my-topic' using gcloud.

GCP
gcloud pubsub topics publish [1] --message '[2]' --attribute [3]=greeting
Drag options to blanks, or click blank then click option'
Amy-topic
BHello, Cloud!
Ctype
Dmy-subscription
Attempts:
3 left
💡 Hint
Common Mistakes
Using the subscription name instead of the topic name.
Incorrect message text or attribute key.