LoginSignup
0
0

More than 1 year has passed since last update.

VM(VirtualBOX+Vagrant)上でchalice localを動かす

Posted at

業務でchaliceを扱うことになりそうなので、動かせる環境を作ってみました。

バージョン

ソフト バージョン
VirtualBOX 6.1.222
Vagrant 2.2.16

VM構築

Vagrantfileに以下を指定してVM立ち上げ

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.network :forwarded_port, guest: 8000, host: 8000
end

chalice localのデフォルトポートが8000なので、ポートフォワーディングしておきます
 IP指定(192.168.33.10:8000)でアクセスできまが、これ追記しておくとlocalhost:8000でアクセスできるようになります

$ vagrant up

VM内

準備

記事執筆時のバージョン

$ python3 --version
Python 3.8.11
$ chalice --version
chalice 1.26.0, python 3.8.11, linux 3.10.0-1160.42.2.el7.x86_64

chaliceプロジェクトの作成

$ chalice new-project helloworld
$ cd helloworld

chaliceプロジェクトのローカル起動

$ chalice local --host=0.0.0.0
Serving on http://0.0.0.0:8000

--host=0.0.0.0を指定します

ホスト(Windows)側からブラウザでアクセス

http://localhost:8000にアクセス

image.png

こんな感じで値が返ってきました!

ちなみに、存在しないパスにアクセスすると403が返ってくるみたいです

image.png

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