追記 (2019/6/5)
一番下に詳細を記述していますが、なんとamplify console側が対応してくださりました!
Amplifyとは
Amplify は、AWS を利用したモバイルやウェブアプリケーションを開発やバックエンドの構成を用意にするフレームワークです。各種AWSサービスとFrontendの連携、Backendの手軽な構成を可能。
構成
Frontend
Vue.js
Backend
AWS AppSync + GraphQL + DynamoDB
環境
- Amplify CLI == 1.7.0
- Vue-CLI == v3.0.0
GraphQL Schema 定義
type Book @model @key(fields: ["category", "title"]){
category: String!
title: String!
price: Int!
}
@model
や@key
はamplify側のディレクティブ
DynamoDBの Partition key や Sort Keyを設定する際に使われるのが@key
ディレクティブ。
最初の要素が Partition Key、その次が Sort Key になる。
GraphQLスキーマのビルド
$ amplify api gql-compile
GraphQL schema compiled successfully.
Edit your schema at /path/to/schema.graphql or place .graphql files
in a directory at /path/to/schema
ローカルではビルドに成功する。
AmplifyConsoleにてデプロイ
ビルド設定は以下の通り
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Localで上手くいっていたビルドでこける
SchemaValidationError: Schema Errors: Unknown directive "key".
ログを詳しく確認してみると
## Install AWS Amplify CLI
RUN /bin/bash -c ". ~/.nvm/nvm.sh && \
npm install -g @aws-amplify/cli@1.5.1"
なるほど。。どうやらConsole側がinstallしている@aws-amplify/cliのバージョンが古いらしい
解決策
amplify.ymlのビルド設定に追記する
~
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- npm install -g @aws-amplify/cli // ---------------- 追記 ----------------
- amplifyPush --simple
~
Frontendからビルドが始まれば問題ないが、連携の都合上Backendのビルドとなってしまうため追記が必要になる。
終わりに
こういったバージョン違いによる不都合はよくあることなので真っ先に疑わないといけないなと反省。
追記 (2019/6/5)
GitHubにissue立てていたのですが、なんと1日足らずで対応してくださりました!!
わざわざTwitterにリプライをくださる神対応ぶり!ありがとうございます!!
Please try again. The new CLI is available in all regions.
— Nikhil Swaminathan (@TheSwaminator) 2019年6月4日