0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CloudEventsを使用したGoogle Cloud Functionsの簡単セットアップ

Posted at

はじめに

本記事は、下記を試したメモです。
cloudevents

cloudeventsをインストール

go install github.com/cloudevents/conformance/cmd/cloudevents@latest

※READMEには、go getと記載がある

パス追加

export PATH=$PATH:$(go env GOPATH)/bin

確認

cloudevents --help

インストール

npm install @google-cloud/functions-framework

index.js追加

index.js
const functions = require('@google-cloud/functions-framework');

functions.cloudEvent('helloCloudEvents', (cloudevent) => {
  console.log(cloudevent.specversion);
  console.log(cloudevent.type);
  console.log(cloudevent.source);
  console.log(cloudevent.subject);
  console.log(cloudevent.id);
  console.log(cloudevent.time);
  console.log(cloudevent.datacontenttype);
});

package.jsonに下記追加

package.json
{
  "scripts": {
    "start": "functions-framework --target=helloCloudEvents"
  }
}

実行

npm start

> start
> npx functions-framework --target=helloCloudEvents

Serving function...
Function: helloCloudEvents
Signature type: cloudevent
URL: http://localhost:8080/

cloudevents実行

cloudevents send http://localhost:8080 --id  abc-123 --source cloudevents.conformance.tool --type foo.bar

実行結果

> start
> npx functions-framework --target=helloCloudEvents

Serving function...
Function: helloCloudEvents
Signature type: cloudevent
URL: http://localhost:8080/
1.0
foo.bar
cloudevents.conformance.tool
undefined
abc-123
undefined
undefined

所感

これを使えばGoogle Cloud Consoleで「保存してデプロイ」を何回もクリックすることは、回避できそう!

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?