あめがえるのITブログ

頑張りすぎない。ほどほどに頑張るブログ。

AWS Amplify CLIをインストールしてみた

AWS AmplifyはGUIじゃほとんど設定ができないようでCLIが必要らしいので入れてみた。

やること

Amplify CLIをインストールする。

前提

実践!

1.Windows版nvmインストール
1-1.下記サイトからnvmインストーラーをダウンロード

https://github.com/coreybutler/nvm-windows/releases



1-2.インストーラーをダブルクリック
 1-2-1.[実行]

 1-2-2.[I accept ...]を選択し、[Next]

 1-2-3.[Next]

 1-2-4.[Next]

 1-2-5.[Install]

 1-2-6.[OK]

 1-2-7.[Finish]

2.Windows版Node.jsインストール
2-1.PowerShellを開き、下記コマンドを実行

> nvm install 18.16.0
Downloading node.js version 18.16.0 (64-bit)...
Extracting node and npm...
Complete
npm v9.5.1 installed successfully.


Installation complete. If you want to use this version, type

nvm use 18.16.0

> nvm use 18.16.0
Now using node v18.16.0 (64-bit)

> npm install -g npm@9
removed 13 packages, and changed 82 packages in 6s


3.Windows版AmplifyCLIインストール
3-1.PowerShellを開き、下記コマンドを実行

> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

> npx @aws-amplify/cli
Need to install the following packages:
@aws-amplify/cli@12.12.0
Ok to proceed? (y) y
The Amplify Command Line Interface (CLI) is a unified toolchain to
create, integrate, and manage the AWS cloud services for your app.

USAGE
  amplify <command> <subcommand> [flags]

COMMANDS
  init           Initialize a new Amplify project
  configure      Configure the CLI to work with your AWS profile
  push           Provisions cloud resources with the latest local changes
  pull           Fetch upstream backend changes from the cloud and updates the local environment
  env            Displays and manages environment related information for your Amplify project
  add            Adds a resource for an Amplify category in your local backend
  status         Shows the state of local resources not yet pushed to the cloud
  plugin         Configure Amplify plugins
  update         Update resource for an Amplify category in your local backend
  publish        Executes amplify push and hosts the frontend app
  remove         Removes a resource for an Amplify category in your local backend
  console        Opens the web console for the selected cloud resource
  delete         Delete the Amplify project
  upgrade        Download and install the latest version of the Amplify CLI
  import         Imports existing resources to your local backend
  override       Override Amplify-generated resources with Cloud Development Kit (CDK)
  diagnose       Capture non-sensitive Amplify backend metadata for debugging purposes
  logout         Logs out of Amplify Studio
  export         Export Amplify CLI-generated backend as a Cloud Development Kit (CDK) stack
  uninstall      Uninstall the Amplify CLI
  serve          Executes amplify push, and then test run the client-side application locally
  mock           Run mock server for testing categories locally
  codegen        Generates GraphQL statements and type annotations
  api            Enable an easy and secure solution to access backend data
  storage        Enable a mechanism for managing user content
  notifications  Configure notifications for your Amplify project
  auth           Enable sign-in, sign-up, and sign-out for your app
  geo            Configure geo resources for your Amplify project
  analytics      Add analytics resources to your Amplify project
  function       Configure function resources for your Amplify project
  hosting        Configure hosting resources for your Amplify project
  interactions   Configure interactions resources for your Amplify project
  predictions    Configure predictions resources for your Amplify project
  build          Builds all resources in the project

FLAGS
  -h | --help  Show help for a command

LEARN MORE
  Visit https://docs.amplify.aws/cli/

npm notice
npm notice New major version of npm available! 9.9.3 -> 10.8.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.0
npm notice Run npm install -g npm@10.8.0 to update!
npm notice

> npm install -g @aws-amplify/cli
added 33 packages in 3m

3-2.インストール確認

> amplify status
🛑 No Amplify backend project files detected within this folder.

Resolution:
Either initialize a new Amplify project or pull an existing project.
- "amplify init" to initialize a new Amplify project
- "amplify pull <app-id>" to pull your existing Amplify project. Find the <app-id> in the AWS Console or Amplify Studio.

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: 9b3b3552-2e80-410f-a774-897276f818d8


4.amplify初期化
※事前に作成しているAmplifyアプリケーションと関連付けする。
4-1.PowerShellを開き、下記コマンドを実行

> amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project amplify
The following configuration will be applied:

Project information
| Name: amplify
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: none
| Source Directory Path: src
| Distribution Directory Path: dist
| Build Command: npm.cmd run-script build
| Start Command: npm.cmd run-script start

? Initialize the project with the above configuration? Yes
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use testvault
Adding backend environment dev to AWS Amplify app: d1wij7bu2gho6s

Deployment completed.
Deployed root stack amplify [ ======================================== ] 4/4
        amplify-amplify-dev-8cd5d      AWS::CloudFormation::Stack     CREATE_COMPLETE                Sun May 19 2024
        AuthRole                       AWS::IAM::Role                 CREATE_COMPLETE                Sun May 19 2024
        UnauthRole                     AWS::IAM::Role                 CREATE_COMPLETE                Sun May 19 2024
        DeploymentBucket               AWS::S3::Bucket                CREATE_COMPLETE                Sun May 19 2024

√ Help improve Amplify CLI by sharing non-sensitive project configurations on failures (y/N) · no

    You can always opt-in by running "amplify configure --share-project-config-on"
Deployment state saved successfully.
√ Initialized provider successfully.
✅ Initialized your environment successfully.
✅ Your project has been successfully initialized and connected to the cloud!
Some next steps:

"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify add <category>" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify console" to open the Amplify Console and view your project status
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud


Pro tip:
Try "amplify add api" to create a backend API and then "amplify push" to deploy everything

※必要なRoleなどが設定される

※devに紐づいているだけわかる、、、

> amplify status

    Current Environment: dev

┌──────────┬───────────────┬───────────┬─────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin │
└──────────┴───────────────┴───────────┴─────────────────┘



感想

とりあえず使う準備は完了したと思う。。。