-
Notifications
You must be signed in to change notification settings - Fork 0
Home
本テキストは遠隔患者モニタリングシステム (https://github.com/codeforjapan/remote-patient-monitoring-api) のインストールの作業ログとなります。
INSTALL.mdの代わりとしてどなたかのお役に立てば幸いです。
- ServerLessアプリケーションのデプロイ用環境の構築
- ServerLessアプリケーション(遠隔患者モニタリングシステムのAPIサーバ)のAWSへのデプロイ
- APIサーバの動作確認
- 遠隔患者モニタリングシステムのダッシュボードのデプロイ
- 遠隔患者モニタリングシステムのダッシュボードのクライアントの実行
■ 環境構築
■■ jqのインストール
■■■ unzipのインストール
■■■ AWSCLIのインストール
■■■ AWSCLIのプロファイル設定
■ remote-patient-monitoring-apiのデプロイ
■■■■ プロダクション環境の設定ファイル作成
■■■■ 開発環境の設定ファイル編集
■■■■ ステージング環境の設定ファイル編集
- リポジトリ
https://github.com/codeforjapan/remote-patient-monitoring-api
このメモはcommit ID 8df0369 を使用して書かれた。
- 参考ドキュメント
https://github.com/codeforjapan/remote-patient-monitoring-api/blob/develop/docs/DEVELOPMENT.md
TBD
(以下、DEVELOPMENT.md に従ってデプロイ環境を構築していく)
https://github.com/codeforjapan/remote-patient-monitoring-api/blob/develop/docs/DEVELOPMENT.md
OS環境としてUbuntu 20.04.1 LTSを用意。
20.04.1 LTS (GNU/Linux 5.4.0-72-generic x86_64)
Dependencyとして以下4つのソフトウェアが挙げられているので順次インストールしていく。
- jq
- node version 12.x
- Serverless
- sed (Ubuntuではプリインストール)
AWSへのデプロイ作業のために以下のソフトウェアのインストールも必要になる。
- aws-cli
- npm-run-all (デプロイに必要)
- typescript (デプロイに必要)
(JSONデータ加工)
$ sudo apt-get install jq
Click to expand
user1@ubuntu:~$ sudo apt-get install jq
[sudo] password for user1:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
jq
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/50.2 kB of archives.
After this operation, 99.3 kB of additional disk space will be used.
Selecting previously unselected package jq.
(Reading database ... 71287 files and directories currently installed.)
Preparing to unpack .../jq_1.6-1ubuntu0.20.04.1_amd64.deb ...
Unpacking jq (1.6-1ubuntu0.20.04.1) ...
Setting up jq (1.6-1ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
user1@ubuntu:~$
(サーバサイドjavascriptランタイム)
現時点でのLTS最新版は14.16.1
だが、システム要件に従い12.x
をインストールする。
NodeSourceのバイナリディストリビューションを使用する。(nvmを使用してもよい)
https://github.com/nodesource/distributions/blob/master/README.md
$ curl -fsSL https://deb.nodesource.com/setup_12.x | sudo bash -
Click to expand
user1@ubuntu:~$ curl -fsSL https://deb.nodesource.com/setup_12.x | sudo bash -
[sudo] password for user1:
## Installing the NodeSource Node.js 12.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://ca.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://ca.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://ca.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://ca.archive.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:5 http://ca.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [955 kB]
Get:6 http://ca.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [768 kB]
Fetched 2,046 kB in 1s (1,419 kB/s)
Reading package lists... Done
## Confirming "focal" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_12.x/dists/focal/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
## Creating apt sources list file for the NodeSource Node.js 12.x repo...
+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_12.x focal main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_12.x focal main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Hit:1 http://ca.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://ca.archive.ubuntu.com/ubuntu focal-updates InRelease
Get:3 http://ca.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://ca.archive.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:5 https://deb.nodesource.com/node_12.x focal InRelease [4,583 B]
Get:6 https://deb.nodesource.com/node_12.x focal/main amd64 Packages [766 B]
Fetched 215 kB in 1s (279 kB/s)
Reading package lists... Done
## Run `sudo apt-get install -y nodejs` to install Node.js 12.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
user1@ubuntu:~$
$ sudo apt-get install -y nodejs
Click to expand
user1@ubuntu:~$ sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 18.1 MB of archives.
After this operation, 93.6 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_12.x focal/main amd64 nodejs amd64 12.22.1-deb-1nodesource1 [18.1 MB]
Fetched 18.1 MB in 2s (12.0 MB/s)
Selecting previously unselected package nodejs.
(Reading database ... 71294 files and directories currently installed.)
Preparing to unpack .../nodejs_12.22.1-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (12.22.1-deb-1nodesource1) ...
Setting up nodejs (12.22.1-deb-1nodesource1) ...
Processing triggers for man-db (2.9.1-1) ...
user1@ubuntu:~$
$ curl -o- -L https://slss.io/install | sudo bash
Click to expand
user1@ubuntu:~$ curl -o- -L https://slss.io/install | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 936 0 --:--:-- --:--:-- --:--:-- 936
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 3897 100 3897 0 0 2135 0 0:00:01 0:00:01 --:--:-- 3672
Installing Serverless!
Downloading binary for version 2.40.0...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 626 100 626 0 0 2086 0 --:--:-- --:--:-- --:--:-- 2086
100 154M 100 154M 0 0 12.9M 0 0:00:11 0:00:11 --:--:-- 15.0M
Added the following to /root/.bashrc:
# Added by serverless binary installer
export PATH="$HOME/.serverless/bin:$PATH"
Added the following to /root/.profile:
# Added by serverless binary installer
export PATH="$HOME/.serverless/bin:$PATH"
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x x
x Serverless Framework successfully installed! x
x x
x To start your first project, please open another terminal and run 都erverless・ x
x x
x You can uninstall at anytime by running 都erverless uninstall・ x
x x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
user1@ubuntu:~$
※ npmを使用してインストールするといくつかエラーを吐く。nodeのメジャーバージョンが古いため?
$ npm install -g serverless
Click to expand
user1@ubuntu:~$ sudo npm install -g serverless
npm WARN deprecated [email protected]: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
/usr/bin/serverless -> /usr/lib/node_modules/serverless/bin/serverless.js
/usr/bin/sls -> /usr/lib/node_modules/serverless/bin/serverless.js
> [email protected] install /usr/lib/node_modules/serverless/node_modules/snappy
> prebuild-install || node-gyp rebuild
prebuild-install WARN install EACCES: permission denied, access '/root/.npm'
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/12.22.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/serverless/node_modules/snappy/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/serverless/node_modules/snappy/.node-gyp'
gyp ERR! System Linux 5.4.0-72-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/lib/node_modules/serverless/node_modules/snappy
gyp ERR! node -v v12.22.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
> [email protected] postinstall /usr/lib/node_modules/serverless/node_modules/protobufjs
> node scripts/postinstall
> [email protected] postinstall /usr/lib/node_modules/serverless/node_modules/aws-sdk
> node scripts/check-node-version.js
> [email protected] postinstall /usr/lib/node_modules/serverless
> node ./scripts/postinstall.js
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x x
x Serverless Framework successfully installed! x
x x
x To start your first project run 'serverless'. x
x x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/serverless/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/serverless/node_modules/snappy):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `prebuild-install || node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
+ [email protected]
added 602 packages from 422 contributors in 45.596s
user1@ubuntu:~$
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/install-cliv2.html
インストールファイルがzip形式で提供されているため、まずunzipをインストールしておく。
$ sudo apt-get install unzip
Click to expand
user1@ubuntu:~$ sudo apt-get install unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
zip
The following NEW packages will be installed:
unzip
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 169 kB of archives.
After this operation, 593 kB of additional disk space will be used.
Get:1 http://ca.archive.ubuntu.com/ubuntu focal/main amd64 unzip amd64 6.0-25ubuntu1 [169 kB]
Fetched 169 kB in 0s (512 kB/s)
Selecting previously unselected package unzip.
(Reading database ... 76179 files and directories currently installed.)
Preparing to unpack .../unzip_6.0-25ubuntu1_amd64.deb ...
Unpacking unzip (6.0-25ubuntu1) ...
Setting up unzip (6.0-25ubuntu1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
user1@ubuntu:~$
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
Click to expand
user1@ubuntu:~$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 41.4M 100 41.4M 0 0 10.4M 0 0:00:03 0:00:03 --:--:-- 10.4M
user1@ubuntu:~$ ls
awscliv2.zip node_modules package-lock.json
user1@ubuntu:~$
user1@ubuntu:~$ unzip awscliv2.zip
Archive: awscliv2.zip
creating: aws/
creating: aws/dist/
inflating: aws/THIRD_PARTY_LICENSES
inflating: aws/install
<中略>
inflating: aws/dist/botocore/data/resourcegroupstaggingapi/2017-01-26/service-2.json
inflating: aws/dist/botocore/data/resourcegroupstaggingapi/2017-01-26/paginators-1.json
user1@ubuntu:~$
user1@ubuntu:~$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
user1@ubuntu:~$
user1@ubuntu:~$ /usr/local/bin/aws --version
aws-cli/2.2.3 Python/3.8.8 Linux/5.4.0-72-generic exe/x86_64.ubuntu.20 prompt/off
user1@ubuntu:~$
AWS CLIのプロファイルを設定する。
$ aws configure --profile your-profile-name
シェル環境変数に使用するプロファイル名を設定する。
$ export AWS_PROFILE="your-profile-name"
※ ログアウトや機器再起動でこのシェル環境変数は消滅するので、必要な場合は$HOME/.bashrcなどに追加しておく。
Click to expand
user1@ubuntu:~$ aws configure --profile my_profile
AWS Access Key ID [None]: XXXXXXXXXXX #キーIDを入力
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXX #アクセスキーを入力
Default region name [None]: ap-northeast-1 #現状、決め打ちでap-northeast-1を指定する
Default output format [None]:
user1@ubuntu:~$
user1@ubuntu:~$ export AWS_PROFILE="my_profile"
user1@ubuntu:~$
※設定された内容は ~/.aws/ の credentials、config に保存されている。
serverlessのデプロイ中でnpm-run-all
が使用されているためインストールが必要。
$ sudo npm install -g npm-run-all
Click to expand
user1@ubuntu:~$ sudo npm install -g npm-run-all
/usr/bin/run-p -> /usr/lib/node_modules/npm-run-all/bin/run-p/index.js
/usr/bin/run-s -> /usr/lib/node_modules/npm-run-all/bin/run-s/index.js
/usr/bin/npm-run-all -> /usr/lib/node_modules/npm-run-all/bin/npm-run-all/index.js
+ [email protected]
added 69 packages from 40 contributors in 3.239s
user1@ubuntu:~$
(メモ:グローバルではなくローカルインストールの方が良さそう)
serverlessのデプロイ中でtsc
が使用されているためインストールが必要。
$ sudo npm install -g typescript
Click to expand
user1@ubuntu:~$ sudo npm install -g typescript
/usr/bin/tsc -> /usr/lib/node_modules/typescript/bin/tsc
/usr/bin/tsserver -> /usr/lib/node_modules/typescript/bin/tsserver
+ [email protected]
added 1 package from 1 contributor in 2.109s
user1@ubuntu:~$
(メモ:グローバルではなくローカルインストールの方が良さそう)
遠隔患者モニタリングシステム (https://github.com/codeforjapan/remote-patient-monitoring-api) をServerLessサービスとしてダウンロード
serverless install -u https://github.com/your-url-to-the-serverless-service
Click to expand
user1@ubuntu:~$ serverless install -u https://github.com/codeforjapan/remote-patient-monitoring-api.git
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Downloading and installing "remote-patient-monitoring-api"...
Serverless: Successfully installed "remote-patient-monitoring-api"
user1@ubuntu:~$
実行ディレクトリ直下に remote-patient-monitoring-api/ というディレクトリツリーができる。
Click to expand
user1@ubuntu:~$ tree --charset=o -L 1 remote-patient-monitoring-api/
remote-patient-monitoring-api/
|-- config
|-- docs
|-- jest.config.js
|-- -jest-dynamodb-config.js
|-- LICENSE
|-- migrations
|-- package.json
|-- package-lock.json
|-- README.md
|-- serverless-dynamodb.yml
|-- serverless-lambda.yml
|-- serverless.yml
|-- src
|-- swagger.ts.old
|-- templates
|-- test
|-- tsconfig.eslint.json
|-- tsconfig-jest.json
|-- tsconfig.json
|-- tsconfig-swagger.json
|-- util
|-- webpack.config.js
`-- webpack-lambda.config.js
7 directories, 16 files
user1@ubuntu:~$
Click to expand
user1@ubuntu:~$ tree --charset=o -L 1 remote-patient-monitoring-api/config/
remote-patient-monitoring-api/config/
|-- configtype.d.ts
|-- dev.json
`-- stg.json.sample
0 directories, 3 files
user1@ubuntu:~$
ステージング環境用のサンプルファイル stg.json.sample
を prd.json
としてコピー。
user1@ubuntu:~/remote-patient-monitoring-api/config$ cp stg.json.sample prd.json
本番環境の設定ファイル config/prd.json
のパラメータを編集。
prd.json
Click to expand
{
"AuthAdminUserPoolDomain": "rpm-admin", # rpmの部分を変更する。AWSリージョン内で一意な名前である必要がある。
"AuthNurseUserPoolDomain": "rpm-nurse", # rpmの部分を変更する。AWSリージョン内で一意な名前である必要がある。
"AuthPatientUserPoolDomain": "rpm-patient", # rpmの部分を変更する。AWSリージョン内で一意な名前である必要がある。
"OauthCallbackURL": "https://stg.remotepatientmonitoring.jp", # FQDNの部分を公開URLのFQDNに変更する。(OAUTHを使わなければ不要?)
"OauthSignoutURL": "https://stg.remotepatientmonitoring.jp", # FQDNの部分を公開URLのFQDNに変更する。(OAUTHを使わなければ不要?)
"Bucket": "remote-patient-monitoring", # remote-patient-monitoring-stgの部分を変更する。AWS上で一意な名前である必要がある。
"DebugMode": "on",
"DBPrefix": "STGRPM-", # STGRPMの部分を変更する。
"AdminUserEmail": "[email protected]", # 管理者のメールアドレスに変更する。
"AdminUserName": "admin",
"SMS_ENDPOINT":"https://sms-host-setting", # 要確認。認証用SMSゲートウェイの設定?
"SMS_SECURITYKEY": "your_securitykey", # 要確認。認証用SMSゲートウェイの設定?
"SMS_ACCESSKEY": "your_access_key", # 要確認。認証用SMSゲートウェイの設定?
"LOGINURL": "https://client.rms.stopcovid19.jp//login/" # 要確認。患者のログイン用公開URLの設定?
}
開発環境の設定ファイル config/dev.json
のパラメータを編集。
dev.json
Click to expand
{
"AuthAdminUserPoolDomain": "dev-icecake-rpm-admin",
"AuthNurseUserPoolDomain": "dev-icecake-rpm-nurse",
"AuthPatientUserPoolDomain": "dev-icecake-patient",
"OauthCallbackURL": "https://dev.icecake-remotepatientmonitoring.jp",
"OauthSignoutURL": "https://dev.icecake-remotepatientmonitoring.jp",
"Bucket": "icecake-remote-patient-monitoring-dev",
"DebugMode": "on",
"DBPrefix": "ICECAKERPM-",
"AdminUserEmail": "[email protected]",
"AdminUserName": "admin",
"SMS_ENDPOINT":"https://sms-host-setting",
"SMS_SECURITYKEY": "your_securitykey",
"SMS_ACCESSKEY": "your_access_key",
"LOGINURL": "https://client.dev.icecake-remotepatientmonitoring.jp/login/"
}
テスト環境の設定ファイル config/stg.json
のパラメータを編集。
stg.json
Click to expand
{
"AuthAdminUserPoolDomain": "stg-icecake-rpm-admin",
"AuthNurseUserPoolDomain": "stg-icecake-rpm-nurse",
"AuthPatientUserPoolDomain": "stg-icecake-patient",
"OauthCallbackURL": "https://stg.icecake-remotepatientmonitoring.jp",
"OauthSignoutURL": "https://stg.icecake-remotepatientmonitoring.jp",
"Bucket": "icecake-remote-patient-monitoring-stg",
"DebugMode": "on",
"DBPrefix": "ICECAKERPM-",
"AdminUserEmail": "[email protected]",
"AdminUserName": "admin",
"SMS_ENDPOINT":"https://sms-host-setting",
"SMS_SECURITYKEY": "your_securitykey",
"SMS_ACCESSKEY": "your_access_key",
"LOGINURL": "https://client.stg.icecake-remotepatientmonitoring.jp/login/"
}
$ npm run deploy
開発、試験、プロダクションの3つのアプリケーション環境がデプロイされる。
※ 初回のデプロイには5分ぐらいかかる
Click to expand
user1@ubuntu:~/remote-patient-monitoring-api/config$ npm run deploy
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - remote-patient-monitoring-dynamoDb-dev
<中略>
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: serverless-cloudformation-sub-variables: Converting AWS CloudFormation Sub variables...
<中略>
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service remote-patient-monitoring.zip file to S3 (4.32 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - remote-patient-monitoring-dev
<中略>
Serverless: Stack update finished...
Service Information
service: remote-patient-monitoring
stage: dev
region: ap-northeast-1
stack: remote-patient-monitoring-dev
resources: 65
api keys:
None
endpoints:
None
functions:
postAdminLogin: remote-patient-monitoring-postAdminLogin-dev
<中略>
create swagger config for dev
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: serverless-cloudformation-sub-variables: Converting AWS CloudFormation Sub variables...
<中略>
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service remote-patient-monitoring.zip file to S3 (4.32 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - remote-patient-monitoring-dev
<中略>
Serverless: Stack update finished...
Running javascript file: ./.lib/src/plugins/generateConfigFile.js
mergeConfigResources
Running command: ./node_modules/.bin/webpack --mode production --progress
Hash: 06447ce9552ae0165c99
Version: webpack 4.44.2
Time: 64869ms
Built at: 05/09/2021 1:33:31 AM
Asset Size Chunks Chunk Names
bundle.js 3.07 MiB 0 [emitted] [big] main
bundle.js.map 8.29 MiB 0 [emitted] [dev] main
index.html 312 bytes [emitted]
Entrypoint main [big] = bundle.js bundle.js.map
[7] (webpack)/buildin/global.js 472 bytes {0} [built]
[18] (webpack)/buildin/module.js 497 bytes {0} [built]
[80] fs (ignored) 15 bytes {0} [built]
[81] ./node_modules/@aws-sdk/util-utf8-browser/dist/es/index.js + 2 modules 13.2 KiB {0} [built]
| 3 modules
[82] ./node_modules/css-loader/dist/cjs.js!./src/webpack/style.css 1.96 KiB {0} [built]
[169] ./src/webpack/config.json 622 bytes {0} [built]
[239] buffer (ignored) 15 bytes {0} [optional] [built]
[241] buffer (ignored) 15 bytes {0} [optional] [built]
[242] crypto (ignored) 15 bytes {0} [optional] [built]
[247] util (ignored) 15 bytes {0} [built]
[249] util (ignored) 15 bytes {0} [built]
[255] buffer (ignored) 15 bytes {0} [optional] [built]
[288] buffer (ignored) 15 bytes {0} [optional] [built]
[291] buffer (ignored) 15 bytes {0} [optional] [built]
[364] ./src/webpack/index.ts + 150 modules 937 KiB {0} [built]
| ./src/webpack/index.ts 734 bytes [built]
| ./src/webpack/style.css 332 bytes [built]
| ./src/webpack/auth.ts 1.5 KiB [built]
| ./src/webpack/swagger.ts 1.47 KiB [built]
| ./src/webpack/config.ts 153 bytes [built]
| + 146 hidden modules
+ 389 hidden modules
Child HtmlWebpackCompiler:
1 asset
Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
[0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/webpack/index.ejs 655 bytes {0} [built]
Service Information
service: remote-patient-monitoring
stage: dev
region: ap-northeast-1
stack: remote-patient-monitoring-dev
resources: 111
api keys:
None
endpoints:
None
functions:
postAdminLogin: remote-patient-monitoring-postAdminLogin-dev
postNurseLogin: remote-patient-monitoring-postNurseLogin-dev
postPatientLogin: remote-patient-monitoring-postPatientLogin-dev
getCenters: remote-patient-monitoring-getCenters-dev
getCenter: remote-patient-monitoring-getCenter-dev
postCenter: remote-patient-monitoring-postCenter-dev
putCenter: remote-patient-monitoring-putCenter-dev
getNurses: remote-patient-monitoring-getNurses-dev
getNurse: remote-patient-monitoring-getNurse-dev
postNurse: remote-patient-monitoring-postNurse-dev
putNurse: remote-patient-monitoring-putNurse-dev
getPatients: remote-patient-monitoring-getPatients-dev
getPatient: remote-patient-monitoring-getPatient-dev
postPatient: remote-patient-monitoring-postPatient-dev
putPatient: remote-patient-monitoring-putPatient-dev
postAcceptPolicy: remote-patient-monitoring-postAcceptPolicy-dev
postInitializePatient: remote-patient-monitoring-postInitializePatient-dev
postSendLoginURLPolicy: remote-patient-monitoring-postSendLoginURL-dev
postStatus: remote-patient-monitoring-postStatus-dev
getStatuses: remote-patient-monitoring-getStatuses-dev
deleteStatus: remote-patient-monitoring-deleteStatus-dev
layers:
None
<中略>
Serverless: Sync bucket: remote-patient-monitoring-dev-swaggerbucket-psbn5pg3dajq:
Serverless: Path: dist
Serverless: File: bundle.js (application/javascript)
Serverless: File: bundle.js.map (application/json)
Serverless: File: index.html (text/html)
user1@ubuntu:~/remote-patient-monitoring-api/config$
util/.secret.json というファイルを作成し、ダッシュボードの管理者ユーザのIDとパスワードを設定する。
$ touch util/.secret.json
$ お好みのエディタ or vi util/.secret.json
{
"auth_user":"adminuser", #任意の文字列
"auth_pass":"Rea11y-Complic8ed" #変えてください。英数大文字小文字両方を含みで8文字以上、さらに数字と記号が最低1つずつ必要
}
ファイルの作成後、以下のコマンドで管理者ユーザが作成される。
$ cd remote-patient-monitoring-api
$ npm run createAdmin
Click to expand
user1@ubuntu:~/remote-patient-monitoring-api$ npm run createAdmin
#--- create admin user
{
"ChallengeName": "NEW_PASSWORD_REQUIRED",
"Session":
<中略>
"ChallengeParameters": {
"USER_ID_FOR_SRP": "catadmin",
"requiredAttributes": "[]",
"userAttributes": "{}"
}
}
<中略>
#--- set new password
{
"ChallengeParameters": {},
"AuthenticationResult": {
"AccessToken":
<中略>
"ExpiresIn": 3600,
"TokenType": "Bearer",
"RefreshToken":
<中略>
"IdToken":
<中略>
}
}
NEW USER CONFIRMED
user1@ubuntu:~/remote-patient-monitoring-api$
後ほど使用するので、最後に表示されるIdTokenの文字列を保存しておくこと。
※なお、前述のAWS CLIの手順でregionを指定していないと以下のエラーになる。
user1@ubuntu:~/remote-patient-monitoring-api/util$ npm run createAdmin
#--- create admin user
You must specify a region. You can also configure your region by running "aws configure".
create failed
user1@ubuntu:~/remote-patient-monitoring-api/util$
以下のコマンドでテストを実行する。 ※ システム全体が正しく動作することを確認するため、E2E(End to End)テストを実行する。
$ npm run test:e2e
Click to expand
user1@ubuntu:~/remote-patient-monitoring-api$ npm run test:e2e
do you delete all cognito data really ? (y/n):y
DELETE Nurses
DELETE Patients
console.log
<中略>
Test Suites: 1 passed, 1 total
Tests: 83 passed, 83 total
Snapshots: 0 total
Time: 88.277 s
Ran all test suites matching /test\/e2e/i.
console.log
<後略>
user1@ubuntu:~/remote-patient-monitoring-api$
MacOSなどローカルでビルドしている場合は以下のスクリプトでアクセス可能。(npm run openSwaggerUIに相当) remote-patient-monitoring-api/util/open_swagger-ui.sh
リモートの非GUI環境でビルドしている場合は以下の手順でUIにアクセス (remote-patient-monitoring-api/util$ cat ./config.json | jq -r '.distribution.SwaggerUIDistribution')
remote-patient-monitoring-api/util/config.jsonの中の以下の値をチェック。 "distribution":{"SwaggerUIDistribution":"XXXXXXX"}
$ aws cloudfront get-distribution --id XXXXXXXX
Click to expand
{
"ETag": "XXXXXXXX",
"Distribution": {
"Id": "XXXXXXXX",
"ARN": "arn:aws:cloudfront::XXXXXXXX:distribution/XXXXXXXX",
"Status": "Deployed",
"LastModifiedTime": "2021-05-09T01:28:34.697000+00:00",
"InProgressInvalidationBatches": 0,
"DomainName": "XXXXXXXX.cloudfront.net",
"ActiveTrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"ActiveTrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"DistributionConfig": {
"CallerReference": "XXXXXXXX",
"Aliases": {
"Quantity": 0
},
"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "swaggerS3",
"DomainName": "XXXXXXXX",
"OriginPath": "",
"CustomHeaders": {
"Quantity": 0
},
"S3OriginConfig": {
"OriginAccessIdentity": "origin-access-identity/cloudfront/XXXXXXXX"
},
"ConnectionAttempts": 3,
"ConnectionTimeout": 10,
"OriginShield": {
"Enabled": false
}
}
]
},
"OriginGroups": {
"Quantity": 0
},
"DefaultCacheBehavior": {
"TargetOriginId": "swaggerS3",
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TrustedKeyGroups": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
]
}
},
"SmoothStreaming": false,
"Compress": true,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"ForwardedValues": {
"QueryString": false,
"Cookies": {
"Forward": "none"
},
"Headers": {
"Quantity": 0
},
"QueryStringCacheKeys": {
"Quantity": 0
}
},
"MinTTL": 0,
"DefaultTTL": 86400,
"MaxTTL": 31536000
},
"CacheBehaviors": {
"Quantity": 0
},
"CustomErrorResponses": {
"Quantity": 0
},
"Comment": "remote-patient-monitoring-dev-swaggerui",
"Logging": {
"Enabled": false,
"IncludeCookies": false,
"Bucket": "",
"Prefix": ""
},
"PriceClass": "PriceClass_100",
"Enabled": true,
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true,
"MinimumProtocolVersion": "TLSv1",
"CertificateSource": "cloudfront"
},
"Restrictions": {
"GeoRestriction": {
"RestrictionType": "none",
"Quantity": 0
}
},
"WebACLId": "",
"HttpVersion": "http2",
"IsIPV6Enabled": true
}
}
}
この出力の中の、DomainNameに対応する値がアクセス先のURLとなる。
"DomainName": "XXXXXXXX.cloudfront.net",
ローカルマシンのブラウザを起動して得られたURLにアクセスする。
個人で試していて課金が心配な人向けに役立つかもしれないリンク。
※ 基本、AWSの無料クレジット枠内に収まるはず。
-
AWSの料金体系とコストの確認方法について https://service.plan-b.co.jp/blog/creative/7312/
-
AWS から請求書を受け取り、その課金されているリソースが見つからないときはどうすればいいですか? https://aws.amazon.com/jp/premiumsupport/knowledge-center/resources-unexpected-charges/
-
AWS の予想請求額をモニタリングする請求アラームの作成 https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html
- 本家
https://docs.google.com/document/d/1ctorno5OTSYuyB7PsYhzPf0cWpjVYZmUWK8StfRoN6Q/edit
- しうまいうまー さんの remote-patient-monitoring-api インストールメモ
https://note.com/siumaiuma/n/n2dd3f3d9a8ab
- ガラスボー さんの Code for Japanの遠隔療養者モニタリングシステムをAWSにデプロイしてみた