AWS Amplify CLIを利用してみた

  • 投稿者:
  • 投稿カテゴリー:aws

nodeのインストール

を参考にnodeをインストール。

# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"

# apt install -y nodejs npm
# npm install n -g
# n stable
# apt purge -y nodejs npm
# exec $SHELL -l
# node -v
v14.15.3

Amplify CLIのインストール

AWS Amplify CLIの使い方〜インストールから初期セットアップまで〜を参考に、amplifyをインストール。

# npm install -g @aws-amplify/cli
...
----------------------------------------
Successfully installed the Amplify CLI
----------------------------------------
...

# amplify -v
Initializing new Amplify CLI version...
Done initializing new version.
Scanning for plugins...
Plugin scan successful
4.40.1

Amplify CLIのセットアップ

# amplify configure
Follow these steps to set up access to your AWS account:

Sign in to your AWS administrator account:
https://console.aws.amazon.com/
Press Enter to continue

Specify the AWS Region
? region:  ap-northeast-1
Specify the username of the new IAM user:
? user name:  amplify-i8W9E
Complete the user creation using the AWS console
https://console.aws.amazon.com/iam/home?region=ap-northeast-1#/users$new?step=final&accessKey&userNames=amplify-i8W9E&permissionType=policies&policies=arn:aws:iam::aws:policy%2FAdministratorAccess
Press Enter to continue

URLにアクセスして、IAMユーザを作成して、アクセスキーなどを入力した。


Enter the access key of the newly created user:
? accessKeyId:  ********************
? secretAccessKey:  ****************************************
This would update/create the AWS Profile in your local machine
? Profile Name:  amplify

Successfully set up the new user.

Amplify環境の構築

CloudFormationテンプレートが作成される。

# amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project amplifyproject
? Enter a name for the environment dev
? Choose your default editor: Vim (via Terminal, Mac OS only)
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using none
? Source Directory Path:  src
? Distribution Directory Path: dist
? Build Command:  npm run-script build
? Start Command: npm run-script start
Using default provider  awscloudformation

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

? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use amplify
Adding backend environment dev to AWS Amplify Console app: d30innubtvg7pq
⠹ Initializing project in the cloud...

CREATE_IN_PROGRESS UnauthRole                       AWS::IAM::Role             Mon Dec 28 2020 00:25:31 GMT+0900 (日本標準時)
CREATE_IN_PROGRESS DeploymentBucket                 AWS::S3::Bucket            Mon Dec 28 2020 00:25:31 GMT+0900 (日本標準時)
CREATE_IN_PROGRESS amplify-amplifyproject-dev-02103 AWS::CloudFormation::Stack Mon Dec 28 2020 00:25:27 GMT+0900 (日本標準時) User Initiated
⠼ Initializing project in the cloud...

CREATE_IN_PROGRESS AuthRole         AWS::IAM::Role  Mon Dec 28 2020 00:25:33 GMT+0900 (日本標準時) Resource creation Initiated
CREATE_IN_PROGRESS UnauthRole       AWS::IAM::Role  Mon Dec 28 2020 00:25:33 GMT+0900 (日本標準時) Resource creation Initiated
CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Mon Dec 28 2020 00:25:33 GMT+0900 (日本標準時) Resource creation Initiated
CREATE_IN_PROGRESS AuthRole         AWS::IAM::Role  Mon Dec 28 2020 00:25:32 GMT+0900 (日本標準時)
⠙ Initializing project in the cloud...

CREATE_COMPLETE AuthRole   AWS::IAM::Role Mon Dec 28 2020 00:25:51 GMT+0900 (日本標準時)
CREATE_COMPLETE UnauthRole AWS::IAM::Role Mon Dec 28 2020 00:25:51 GMT+0900 (日本標準時)
⠸ Initializing project in the cloud...

CREATE_COMPLETE amplify-amplifyproject-dev-02103 AWS::CloudFormation::Stack Mon Dec 28 2020 00:25:56 GMT+0900 (日本標準時)
CREATE_COMPLETE DeploymentBucket                 AWS::S3::Bucket            Mon Dec 28 2020 00:25:53 GMT+0900 (日本標準時)
✔ Successfully created initial AWS cloud resources for deployments.
✔ 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 publish" to deploy everything

# amplify status

Current Environment: dev

| Category | Resource name | Operation | Provider plugin |
| -------- | ------------- | --------- | --------------- |

IAMロールとS3が作成されていることがわかった。ここからアプリケーションに必要な機構を追加していく仕組みとなっている。