Google App Engineで「Hello World!」なんてしてみた
IT系ニュース見てたら、
「GoogleがAmazonみたいにインフラをみんなが使えるようにうんちゃらかんちゃら」とあり、
「ほぉ〜!」と思ったところ
「限定1万人で」みたいなことも見えたので急いで登録してみました。
登録当初は「使えるようになったら連絡するね」とGoogleから言われたんですが
数日後、「使えるようになったよ」とメールが来てたのでSDKも落として使ってみました。
Googleのドキュメント見つつ、とりあえず、Pythonもよく知らんので
まずは、コピペがてらHelloWorldしてみることに。
まずは適当にディレクトリを切って、その配下にhelloworld.pyを作成します。
helloworld.py
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
Content-type要るんですね。
同じディレクトリにapp.yamlも作成します。
app.yaml
application: helloworld
version: 1
runtime: python
api_version: 1handlers:
- url: /.*
script: helloworld.py
あとは作成したディレクトリのある場所で下記のコマンドを打つと
http://localhost:8080で確認できます。
# dev_appserver.py helloworld/
Allow dev_appserver to check for updates on startup? (Y/n): Ydev_appserver will check for updates on startup. To change this setting, edit /Users/xxxxx/.appcfg_nag
INFO 2008-04-14 23:07:13,326 appcfg.py] Checking for updates to the SDK.
INFO 2008-04-14 23:07:14,339 appcfg.py] The SDK is up to date.
WARNING 2008-04-14 23:07:14,339 datastore_file_stub.py] Could not read datastore data from /var/folders/C2/C2SqSVziEYOlAlZObkkdxE+++TI/-Tmp-/dev_appserver.datastore
WARNING 2008-04-14 23:07:14,340 datastore_file_stub.py] Could not read datastore data from /var/folders/C2/C2SqSVziEYOlAlZObkkdxE+++TI/-Tmp-/dev_appserver.datastore.history
INFO 2008-04-14 23:07:14,344 dev_appserver_main.py] Running application helloworld on port 8080: http://localhost:8080
INFO 2008-04-14 14:07:20,836 dev_appserver.py] "GET / HTTP/1.1" 200 -
INFO 2008-04-14 14:07:20,838 dev_appserver_index.py] Updating /Users/xxxxx/Documents/GoogleApp/helloworld/index.yaml
INFO 2008-04-14 14:07:20,965 dev_appserver.py] "GET /favicon.ico HTTP/1.1" 200 -
Googleのサーバへは下記のコマンドでUploadできます
# appcfg.py update helloworld/
Email:
Password for :
Saving authentication cookies to /Users/xxxxx/.appcfg_cookies
Scanning files on local disk.
Initiating update.
2008-04-14 23:11:55,373 ERROR appcfg.py:1070 An unexpected error occurred. Aborting.
Error 403: --- begin server output ---
You do not have permission to modify this app.
--- end server output ---
あれあれ??
なんか怒られる。。。
もう一回、ドキュメントとかを確認してみると、
Googleで作成したアプリケーション名をhelloworldにしてなかったので
app.yamlに書かれてるapplicationと違うので怒られてたみたい。
なので、もう一回、app.yamlを修正して、あげ直し。
# appcfg.py update tryout-lab/
Loaded authentication cookies from /Users/tryout/.appcfg_cookies
Scanning files on local disk.
Initiating update.
Cloning 1 application file.
Closing update.
Uploading index definitions.
はい、うまいこと行きました。
http://app-id.appspot.comで見てもOK。
なかなか興味深いです。コマンドも用意されててアップも簡単みたいだし。
pythonの勉強も少ししつつ、触っていきたいと思います。