この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
モバイルアプリサービス部の五十嵐です。
前回のサーバレスアプリケーションフレームワーク JAWS を使ってみる | Developers.IOでは、JAWSのQuick Startを紹介しました。
今回は、JAWSのコマンドから、JAWSの機能をOverViewしてみたいと思います。
Project Commands
$ jaws project create
- JAWSプロジェクトを作成して雛形のファイルを作成します。
- CloudFormationでAWSにIAMロールなどのリソースを作成します。
Usage: project [options]
Work with JAWS Project. Valid 's: create
Options:
-h, --help output usage information
-d, --dont-exe-cf Don't execute CloudFormation, just generate it
-s, --stage Name for the stage to create
-r, --region Name of AWS region to use
-u, --domain domain ex: myapp.com
-n, --proj-name Name for the new project
-e, --email Notification email to use in CloudFormation
-p, --aws-profile Admin AWS profile as defined in ~/.aws/credentials to use
環境(dev,production,など)やリージョン、ドメイン、CloudFormationのNotificationメールアドレス、クレデンシャルなどが設定できることが分かります。
Module Commands
$ jaws module create
- Lambda functionの雛形とAPI Gatewayの設定を
aws_modules
フォルダに作成します。
Usage: module [options] [params]
aws-module commands
Valid 's: create
create: create aws-module action. Module will be created if DNE. create
Ex: jaws module create users list
Options:
-h, --help output usage information
-l, --lambda [create]: create lambda. Default is create lambda and endpoint.
-e, --endpoint [create]: create API Gateway endpoint. Default is create lambda and endpoint.
-r, --runtime [create]: lambda runtime. Valid: nodejs
-p, --package-manager [create]: Select package manager used when creating awsm for publishing. Valid options: npm
lambdaだけ、あるいはendpointだけを作成することもできます。 runtimeは今のところNode.jsのみ対応しているようです。 次に登場しますが、awsmを公開するのに使うパッケージマネージャを選択できます。 しかし手元の環境ではこれらのオプションは動作しませんでした。
$ jaws postinstall
- awsm(Amazon Web Services Modules)というLambda functionのライブラリをダウンロードして、
aws_modules
フォルダに雛形を作成します。
Usage: postinstall [options]
Performs automation when an aws-module is installed via a package manager
Options:
-h, --help output usage information
先にnpm install
でプロジェクト内にパッケージをダウンロードしてから、postinstall
を行うことで公開されているawsmをインポートできます。
Region Commands
$ jaws region create
- プロジェクトに新しいリージョンを追加します。
Usage: region [options]
Work with AWS Regions. Valid 's: create
Options:
-h, --help output usage information
-d, --dont-exe-cf Don't execute CloudFormation, just generate it
-s, --stage Name for the stage to be created in the region
-r, --region Name of AWS region to use
-p, --aws-profile Admin AWS profile as defined in ~/.aws/credentials to use
Stage Commands
$ jaws stage create
- リージョンに新しい環境(dev,production,など)を追加します。
Usage: stage [options]
Work with JAWS stages in a region. Valid 's: create
Options:
-h, --help output usage information
-d, --dont-exe-cf Don't execute CloudFormation, just generate it
-s, --stage Name for the stage create
-r, --region Name of aws region to use
-p, --aws-profile Admin AWS profile as defined in ~/.aws/credentials to use
Dash Commands
$ jaws dash
- 対話的なダッシュボードを使ってリソースをデプロイします。
Usage: dash [options]
View a project summary and select resources to deploy.
Options:
-h, --help output usage information
ENV Commands
$ jaws env
- 環境変数のCRUDコマンドです。
Usage: env [options] [key] [val]
Manage env vars for stage & region. can be "all" can be "local"
Valid 's:
list: vars for stage and region. jaws env list
Ex: jaws env list prod all
get: var value for stage and region. jaws env get
Ex: jaws env get prod all JAWS_STAGE
set: var value for stage and region. jaws set env
Ex: jaws env set prod us-east-1 TABLE_NAME users
unset: var value for stage and region. jaws env unset
Ex: jaws unset prod us-east-1 TABLE_NAME
Options:
-h, --help output usage information
Tag Commands
非推奨とあるので省略します(エラーになりました。)
Deploy Commands
$ jaws deploy [stage] [region]
jaws dash
コマンドのようにインタラクティブではなく、type、stage、regionを指定してデプロイします。
Usage: deploy [options] [stage] [region]
Deploy a lambda function (type lambda), a REST API (endpoint), or provision AWS resources (resources) for the specified stage. By default will tag and deploy type at cwd
Options:
-h, --help output usage information
-t, --tags Deploy all lambdas tagged as deployable in their jaws.json. Default is to just deploy cwd
-d, --dont-exe-cf Don't execute the lambda cloudformation, just generate it. Zips will be uploaded to s3
Run Commands
$ jaws run
- ローカル環境でLambdaをテストします。Lambdaの処理ロジックはhandlerのコードと分離しておき、Node.jsならmochaなどテストフレームワークを使うといいでしょう。
Usage: run [options]
Run the lambda in CWD locally
Options:
-h, --help output usage information
所感
注目はawsmですね。JAWSのライブラリでありサンプルとしても使えると思いますので、次回はこれで何か簡単なアプリケーションを作ってみようと思います。また、複数の環境へのデプロイが用意されているのはテストやデプロイ戦略的にも便利そうですね。