0
0
GCPcloud~10 mins

Event triggered functions in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Event triggered functions
Event Occurs
Cloud Event Detected
Trigger Function
Function Executes
Function Completes
Optional: Emit Result or Log
When an event happens in the cloud, it triggers a function to run automatically, which then executes and finishes its task.
Execution Sample
GCP
def hello_gcs(event, context):
    print(f"File {event['name']} uploaded.")
This function runs when a file is uploaded to Cloud Storage and prints the file name.
Process Table
StepEventFunction TriggeredActionOutput
1File uploaded to bucket 'photos'hello_gcsFunction startsNo output yet
2N/Ahello_gcsReads event data: file name 'image1.png'No output yet
3N/Ahello_gcsPrints message: 'File image1.png uploaded.'Message logged
4N/Ahello_gcsFunction completesExecution ends
💡 Function completes after processing the event triggered by file upload.
Status Tracker
VariableStartAfter Step 2After Step 3Final
event{}{'name': 'image1.png', 'bucket': 'photos'}{'name': 'image1.png', 'bucket': 'photos'}{'name': 'image1.png', 'bucket': 'photos'}
context{}context objectcontext objectcontext object
Key Moments - 3 Insights
Why does the function run automatically without being called explicitly?
Because the cloud platform detects the event (like a file upload) and triggers the function automatically, as shown in execution_table step 1.
What information does the function receive about the event?
The function receives event data like the file name and bucket, visible in execution_table step 2 and variable_tracker for 'event'.
Does the function run before or after the event happens?
The function runs after the event happens; the event triggers the function, as shown in concept_flow and execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is printed by the function at step 3?
A"Function starts"
B"File image1.png uploaded."
C"File uploaded to bucket 'photos'"
D"Execution ends"
💡 Hint
Check the 'Action' and 'Output' columns at step 3 in execution_table.
At which step does the function complete its execution?
AStep 4
BStep 3
CStep 2
DStep 1
💡 Hint
Look at the 'Action' column for 'Function completes' in execution_table.
If the event was a file deletion instead of upload, what would change in the execution_table?
AThe function would not trigger at all.
BThe function would print the same upload message.
CThe event description in step 1 would change to file deletion.
DThe function would complete earlier.
💡 Hint
Focus on the 'Event' column in execution_table step 1.
Concept Snapshot
Event triggered functions run automatically when a cloud event happens.
They receive event data and context as input.
The function executes its code and then finishes.
Common events: file upload, database change, message arrival.
No manual call needed; cloud detects and triggers.
Useful for automation and reacting to changes.
Full Transcript
Event triggered functions in cloud platforms run automatically when specific events occur, such as a file upload to storage. The cloud detects the event and triggers the function, passing event details like file name and bucket. The function executes its code, for example printing a message about the uploaded file, and then completes. This process requires no manual invocation, enabling automatic responses to cloud events.