Closed10

M1 MacでAmplify開発環境を最速で構築する

はちはち

最速と言いつつ、やったこと調べて出てきた他の方の記事などを備忘録として載せていきます。
ケースは以下の通りです。
・MacbookproでAmplify+reactで開発中の環境を、新規購入したMac mini (M1)に移行

はちはち

Homebrewインストール

Homebrewをアーキテクチャ毎に管理する

  • 【arm64e】 /opt/homebrew/bin/brew
  • 【x86_64】 /usr/local/bin/brew

インストール

sudo chown -R $(whoami) /opt/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C /opt/homebrew

パス関連

echo $SHELL
touch ~/.zshrc
echo 'export PATH=$PATH:/opt/homebrew/bin' >> ~/.zshrc
source ~/.zshrc
which brew

アップデート

brew --version
brew update
brew --version

参照

https://zenn.dev/junjunjunk/articles/4b230519d87de4
https://qiita.com/yasukom/items/3f9f7eb98dfdd20d9704

はちはち

Githubからソースコードを取得

ssh鍵の設定

mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa

ssh鍵の設定(github画面で)

右上アカウントボタン押下。
Sttings押下。
SSH and GPG keysを押下。
New SSH keyを押下。
keyの箇所に以下のコマンドでコピーしてきた公開鍵を貼り付け。

pbcopy < ~/.ssh/id_rsa.pub 

接続確認

ssh -T git@github.com

~/.ssh/configの作成

ssh鍵にid_rsa以外の名前を付けた際には以下の内容でconfigファイルを作成する。

Host github github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_github #鍵のファイル名
  User git

再度接続確認

ssh -T git@github.com

以下のメッセージが出たら接続完了

Hi xxxxxxxx! You've successfully authenticated, but GitHub does not provide shell access.

ソースコード取得

mkdir -p projects/project_folder_name
cd projects/project_folder_name
git clone git@github.com:XXXXX/repository_name.git

開発ブランチの作成

masterブランチからdevelopブランチを作成

git checkout -b develop
はちはち

amplifyの既存の構成をpull

基本的にAWSコンソールのAmplifyページ、Backend environmentsのLocal setup instructionsをコピペするだけ。

amplify pull 開発環境

amplify pull --appId xxxxxx --envName dev

amplify pull 本番環境

amplify pull --appId xxxxxx --envName prod

確認

amplify env list
| Environments |
| ------------ |
| *prod        |
| dev          |
はちはち

package.jsonの内容をインストールする

yarnでインストール

yarn install

npmでインストール

npm install
はちはち

pipenvをインストールする

Amplify functionでpythonを使っているため、pipenvがない状態でamplify pushすると以下のエラーが出る。

You must have pipenv installed and available on your PATH as "pipenv". It can be installed by running "pip3 install --user pipenv".
✖ An error occurred when pushing the resources to the cloud

Missing required dependencies to package function_name
An error occurred during the push operation: Missing required dependencies to package function_name

Pipfileで指定されたパッケージをインストールするためのpipenvがないよと言われているため、これをインストールする。

pipenv --version
brew install pipenv 
pipenv --version

すると以下にインストールされる。

which pipenv
/opt/homebrew/bin/pipenv
はちはち

git configの設定

git commitする際に以下のエラーがでた。

Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address

gitが誰がコミットしてきているのかわからないために出る。
指示された通り、以下のコマンドでgit configにemailとnameを入力する。

 git config --global user.email "you@example.com"
 git config --global user.name "Your Name"

ちなみに入力する際は""は不要。

このスクラップは2021/05/15にクローズされました