LoginSignup
430
347

More than 1 year has passed since last update.

Herokuの無料枠が廃止になるのでDeta.shへ移行する

Last updated at Posted at 2022-08-29

追記(2023/3/11)

約半年ほどDeta.shで簡単なサービスを運用していたが、先日Deta.shに大幅なアップデートがあり、仕様が大きく変わった。
これによりREST APIを公開して運用することができなくなった。(できなくはないが必ずヘッダにAPIキーを指定する必要がある。そのため例えばLINE Messaging APIのバックエンドとしては使用不可)
Detaは”Personal Cloud”を思想に掲げているらしく、何らかのサービスのバックエンドとして使うにはちょっと使い勝手が悪くなってしまった。
というわけで、自分の使い方には合わなくなったため現在はAWSへ移行している。

HerokuのFree Planが終了するらしい(泣)

Starting November 28, 2022, we plan to stop offering free product plans and plan to start shutting down free dynos and data services. We will be sending out a series of email communications to affected users.

2022/11/28までに有料版にアップグレードしてねとのことらしい。

Deta.sh

Deta.shへ移行した

The Cloud for Doers & Dreamers.

Deta.shは無料で使えるクラウドプラットフォーム。
デプロイしたアプリはAWS上に展開されるようだ。
主に3つのサービスが使える。

  1. クラウドランタイム (Deta Micors)
  2. 容量無制限のNoSQLデータベース (Deta Base)
  3. 1アカウントあたり10GBまでのクラウドストレージ(Deta Drive)
  • 無料(そもそも有料プランが存在しない)
  • Herokuと違い30分でスリープする制限はない
  • RuntimeにはPythonかNodeが使用できる

CLIのインストール

curl -fsSL https://get.deta.dev/cli.sh | sh

ログイン

deta login

アプリの作成

deta new --python app_hello

エンドポイントのURLその他が表示される

{
    "name": "app_hello",
    "id": "xxxxxxx",
    "project": "xxxxxx",
    "runtime": "python3.9",
    "endpoint": "https://xxxxx.deta.dev",
    "region": "ap-southeast-1",
    "visor": "disabled",
    "http_auth": "disabled"
}

ファイル構成はプロジェクトのディレクトリ直下に2ファイル:

├── main.py
├── requirements.txt
main.py
import os

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def say_hello():
  return {"message": "Hello, Deta.sh"}

requirements.txt
fastapi

デプロイ・動作確認

用意できたらデプロイ
deta deploy

動作確認
curl https://<xxxx>.deta.dev/

環境変数のセット・デプロイ

.env
ANY_ENVVAR_HERE=xxxx

deta update -e .env
deta deploy
環境変数をセットした後に変更を反映するためもう一度デプロイする必要があるが、ファイルに差分がないとデプロイできないため、main.pyを編集してからもう一度デプロイする。

ログの取得

deta logs

ドメイン

Deta.shのダッシュボードから、任意のサブドメインの設定や、自分のドメインを設定できる。
d.png

430
347
2

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
430
347