Event

Your Google Cloud Function can be triggered by different event sources. Those event sources can be defined and configured with the help of the event event.

Event events

This example sets up a pubSub event which will trigger the first function whenever a message is published to the my-topic topic.

# serverless.yml

functions:
  first:
    handler: pubSub
    events:
      - event:
          eventType: providers/cloud.pubsub/eventTypes/topic.publish
          resource: 'projects/${self:provider.project, ""}/topics/my-topic'
// index.js

exports.pubSub = (event, callback) => {
  console.log('Hello World!');
  callback();
};

Note: See the documentation about the function handlers to learn how your handler signature should look like to work this type of event.

Edit this page

Event

Your Google Cloud Function can be triggered by different event sources. Those event sources can be defined and configured with the help of the event event.

Event events

This example sets up a pubSub event which will trigger the first function whenever a message is published to the my-topic topic.

# serverless.yml

functions:
  first:
    handler: pubSub
    events:
      - event:
          eventType: providers/cloud.pubsub/eventTypes/topic.publish
          resource: 'projects/${self:provider.project, ""}/topics/my-topic'
// index.js

exports.pubSub = (event, callback) => {
  console.log('Hello World!');
  callback();
};

Note: See the documentation about the function handlers to learn how your handler signature should look like to work this type of event.