SlideShare a Scribd company logo
Firebaseの運用に役立つTips5
TetsuroYoshikawa
@iBotchME
ytetsuro
1/16
Firebaseの運用に役立つTips5
①FirebaseLocalEmulatorSuiteで開発しましょう
②CloudFirestore-作成‧更新‧読取時間-
③Authentication-カスタムクレームをつかいましょう-
④Hosting-CloudLoggingの設定-
⑤CloudFunctions-CloudLoggingをみましょう-
2/16
①FirebaseLocalEmulatorSuiteで開発しましょう
FirebaseLocalEmulatorSuiteとは、
以下をローカルでビルドおよびテストするデベロッパー
向けのツールセット。
Cloud Firestore Cloud Functions
Cloud Pub/Sub
Realtime Database
Authentication
Hosting
3/16
①FirebaseLocalEmulatorSuiteで開発しましょう
テストがしやすくなる。
serviceAccount.jsonを配布しなくても開発できる。
オフラインでも開発できる。
セキュリティルールのカバレッジが出力できる。
謎の restoreindex更新などが発生しづらくなる。
etc...
https:// rebase.google.com/docs/emulator-suite?hl=ja
4/16
①FirebaseLocalEmulatorSuiteで開発しましょう
導入手順
rebase.jsonの設定をする
アプリケーションでemulatorを参照するようにする
簡単☺
https:// rebase.google.com/docs/emulator-suite/install_and_con gure?hl=ja
https:// rebase.google.com/docs/emulator-suite/connect_ restore?hl=ja
5/16
②CloudFirestore-作成‧更新‧読取時間-
Firestoreでは作成、更新、読取の情報を保持してくれ
ているので覚えておくと障害調査時に役立ちます。
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();
const updateDate = (await db.doc('/foo/bar').get())
.updateTime
.toDate();
console.log(updateDate); // 2021-03-17T16:58:34.090Z
6/16
③Authentication-カスタムクレームをつかいましょう-
Authenticationから発行されるトークンはJWTなのでカ
スタムクレームを使うと以下の恩恵が得られる。
restoreやrealtimedatabaseのセキュリティルール
でreadが削れる。
サービスをまたがってユーザの認証に関わる情報を伝
えられる。
※1,000byte以下の制約があるので、要件に合致する場合に限る。
7/16
③Authentication-カスタムクレームをつかいましょう-
const admin = require('firebase-admin');
admin.initializeApp();
const uid = "IamUser";
admin.auth().setCustomUserClaims(uid, {
role: 'Admin',
companyId: 'foo'
});
8/16
④Hosting-CloudLoggingの設定-
Hostingはデフォルトでリクエストログがないため、以
下の問題が発生しがちです。
サービスのアクセスの多い時間が分からない。
どこで障害が発生したのかわからない。
etc...
https:// rebase.google.com/docs/hosting/web-request-logs-and-metrics
9/16
④Hosting-CloudLoggingの設定-
Hostingのリクエストログを取る設定をしましょう。
10/16
⑤CloudFunctions-CloudLoggingをみましょう-
Firebaseコンソールのログは処理を一意に判別する方
法がないため扱いづらいです。
最初に発生したのstartedに対する nishedはどれ?🤔
11/16
⑤CloudFunctions-CloudLoggingをみましょう-
CloudLoggingよりログを確認すると、ログに一意な
execution_idが付与されているので便利です。
12/16
⑤CloudFunctions-CloudLoggingをみましょう-
ヒストグラムも出してくれるので見やすい。
13/16
⑤CloudFunctions-CloudLoggingをみましょう-
CloudLoggingはCLIから読み取ることも可能です。
そのため、jqやpecoと組み合わせて障害の影響範囲の
調査などをするときに便利です。☺
gcloud logging read 
'resource.type="cloud_function"' 
--limit 10 --format json | jq '...'
14/16
まとめ
エミュレータを使って閉じた環境で開発しましょう。
CloudFirestoreは操作時間を記録していることを覚え
ておくと障害調査に役立つ。
認証情報はカスタムクレームで扱うと良いかも。
HostingのCloudLogging連携大切。
CloudLoggingでログを見ましょう。
15/16
OptimindではWebアプリケーション
エンジニアを募集しています
Firebase環境での開発が現時点ではメインなので興味が
ある方は是非!
今は興味がない方でもお気軽にお話ししましょう。
https://www.wantedly.com/projects/583309
16/16

More Related Content

PPTX
Must have tools for windows azure
PPTX
The Experience of Java on Kubernetes with Microservices from HackFest
PPTX
Quoi de neuf Dans Azure ?
PPTX
All you need to know about Microsoft Ignite 2016
PDF
Rakuten openstack
PDF
Expert Day 2019 - Introduction
DOCX
Iis6 configuration with was (installed on linux)
PPT
Infrastrucutre As Code
Must have tools for windows azure
The Experience of Java on Kubernetes with Microservices from HackFest
Quoi de neuf Dans Azure ?
All you need to know about Microsoft Ignite 2016
Rakuten openstack
Expert Day 2019 - Introduction
Iis6 configuration with was (installed on linux)
Infrastrucutre As Code

What's hot (19)

PPTX
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
DOCX
Np web ii-devel-installation
PPTX
Insider Dev Tour Taipei 2019 - Future proof your desktop apps with .net core
PDF
FIWARE Tech Summit - How To Deploy Context Broker in 10 Minutes
PDF
10 Reasons Why Cloud Foundry Rocks!
PPTX
Azure Web PubSub Serviceを触ってみた
PDF
2018년 3월 정기 세미나 - March 2018 Ops Meetup 후기
KEY
勉強会・講演資料
PPTX
My sql installation
PPTX
3# meetup de kubernetes em Brasilia
PPTX
Spryks (code generators)
PPTX
Introduction to Puppet Enterprise 2016.2
PPTX
OWASP CSRF Protector
PDF
Install edq on linux
PDF
Building your own PaaS using Apache Stratos
PPTX
Azure Artifactsを触ってみよう
PPTX
Martin Hujer: PHP ve Windows Azure cloudu
PDF
WAF In DevOps DevOpsFusion2019
PPTX
Csrf protector
"Don’t Run with Scissors: Serverless Security Survival Guide" | Hillel Solow,...
Np web ii-devel-installation
Insider Dev Tour Taipei 2019 - Future proof your desktop apps with .net core
FIWARE Tech Summit - How To Deploy Context Broker in 10 Minutes
10 Reasons Why Cloud Foundry Rocks!
Azure Web PubSub Serviceを触ってみた
2018년 3월 정기 세미나 - March 2018 Ops Meetup 후기
勉強会・講演資料
My sql installation
3# meetup de kubernetes em Brasilia
Spryks (code generators)
Introduction to Puppet Enterprise 2016.2
OWASP CSRF Protector
Install edq on linux
Building your own PaaS using Apache Stratos
Azure Artifactsを触ってみよう
Martin Hujer: PHP ve Windows Azure cloudu
WAF In DevOps DevOpsFusion2019
Csrf protector
Ad

Similar to Firebaseの運用に役立つTips5 (20)

PDF
AzureDevOps_ProjectManagement_Patrick.pdf
PDF
AzureDevOps_Developer.pdf
PPTX
Java and windows azure cloud service
PPTX
06 integrating extra features and looking forward
PPTX
Serverless Pune Meetup 1
PPTX
Go…Running Kentico CMS on Windows Azure
PDF
PuppetCamp Verona 2013 - Razor, Puppet & VMware
PDF
HDinsight Workshop - Prerequisite Activity
PPTX
Implementing FaaS on Kubernetes using Kubeless
PPTX
Deploying Artifacts to Oracle Cloud with FlexDeploy
PDF
Azure Cookbook Recipes To Create And Maintain Cloud Solutions In Azure 1st Ed...
PPTX
Intro to Spring Boot and Spring Cloud OSS - Twin Cities Cloud Foundry Meetup
PDF
WebLogic FAQs
PDF
Securing Legacy CFML Code
PPTX
Microservices on Application Container Cloud Service
PPTX
Getting Started with PaaS
PPTX
Serverless Pune meetup 3
PDF
Using jca salesforce adapter with soa suite
PPTX
Getting Started with Platform-as-a-Service
PDF
DevOps and compliance and security
AzureDevOps_ProjectManagement_Patrick.pdf
AzureDevOps_Developer.pdf
Java and windows azure cloud service
06 integrating extra features and looking forward
Serverless Pune Meetup 1
Go…Running Kentico CMS on Windows Azure
PuppetCamp Verona 2013 - Razor, Puppet & VMware
HDinsight Workshop - Prerequisite Activity
Implementing FaaS on Kubernetes using Kubeless
Deploying Artifacts to Oracle Cloud with FlexDeploy
Azure Cookbook Recipes To Create And Maintain Cloud Solutions In Azure 1st Ed...
Intro to Spring Boot and Spring Cloud OSS - Twin Cities Cloud Foundry Meetup
WebLogic FAQs
Securing Legacy CFML Code
Microservices on Application Container Cloud Service
Getting Started with PaaS
Serverless Pune meetup 3
Using jca salesforce adapter with soa suite
Getting Started with Platform-as-a-Service
DevOps and compliance and security
Ad

Recently uploaded (20)

PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Digital Logic Computer Design lecture notes
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Geodesy 1.pptx...............................................
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
PPT on Performance Review to get promotions
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Digital Logic Computer Design lecture notes
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
additive manufacturing of ss316l using mig welding
Internet of Things (IOT) - A guide to understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CH1 Production IntroductoryConcepts.pptx
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Geodesy 1.pptx...............................................
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
PPT on Performance Review to get promotions

Firebaseの運用に役立つTips5