LoginSignup
2
1

More than 1 year has passed since last update.

amplify CLI の Headless mode で pull するとき auth リソースが存在するとエラーで落ちる

Last updated at Posted at 2021-07-02

前提

  • Amplify CLI バージョン 4.52.0

問題

AWS Amplify を使ったアプリを CI で自動ビルドするときなどは amplify pull を Headless mode で使って、設定を自動化します。公式ドキュメントの Headless mode の説明に従って、スクリプトを書くと次のような感じになります。

#!/bin/bash

AMPLIFY="..." # 略
FRONTEND="..." # 略
PROVIDERS="..." # 略

amplify pull --amplify $AMPLIFY --frontend $FRONTEND --providers $PROVIDERS --yes

しかし、 pull 対象の Amplify に auth リソース (Cognito) が設定されていると、以下のようなエラーが出る場合があります。

Failed to pull the backend.
auth headless is missing the following inputParams userPoolId, webClientId, nativeClientId

原因

amplify pull--yes オプションを付けていると、 pull 後に auth リソースの初期化が実行されることが原因です。試しに --yes オプションを付けないとどういう動作になるかというと、

% amplify pull --amplify $AMPLIFY --frontend $FRONTEND --providers $PROVIDERS
Amplify AppID found: <your_app_id>. Amplify App name is: my_app
Backend environment dev found in Amplify Console app: my_app
? Do you plan on modifying this backend? (Y/n)

最後に「バックエンドを更新する予定があるか?」という質問が出ていることが分かります。

この質問に手動で Y と回答した場合は、 そのまま処理が成功するのですが、不思議なことに --yes オプションを使った場合は、 その後、auth リソースの初期化が走り、さらに初期化に必要な設定が見つからずに、エラーになるようです(そもそも初期化が走るのはバグのような気もしますが...)。

対策

「バックエンドを更新する予定はない」という設定で amplify pull を実行させるのが対策になります。

しかし、2021年7月現在、amplify pull の Headless mode には、バックエンドを更新する予定の有無を設定するオプションは存在しません。また、「バックエンドを更新するか?」という質問に no で回答するオプションもありません。

ということで、強引にパイプで n を突っ込む、次のワークアラウンドが対策となります。

echo n | amplify pull --amplify $AMPLIFY --frontend $FRONTEND --providers $PROVIDERS

参考

2
1
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
2
1