DynamoDBのテーブルが必要なため、マネジメントコンソールまたはCLIテーブルを作る。テーブル名はmessagesとし、プライマリーキーは文字列型のuuidとする。
aws dynamodb create-table --table-name 'messages' \
--attribute-definitions '[{"AttributeName":"uuid","AttributeType": "S"}]' \
--key-schema '[{"AttributeName":"uuid","KeyType": "HASH"}]' \
--provisioned-throughput '{"ReadCapacityUnits": 1,"WriteCapacityUnits": 1}'ローカルでの実行時にリモートのDynamoDBにアクセスするため、DynamoDBにアクセス可能なIAMユーザーのクレデンシャルをapp/.envファイルに書くか、exportする。
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
イメージのビルドして起動する。
cd app
docker-compose build
docker-compose uphttp://localhost:5000からアプリケーションにアクセスする。
docker-compose downDynamoDBのテーブルはCDK内に含めているので既に作成した場合は削除する。
aws dynamodb delete-table --table-name 'messages'リポジトリを作成する。
aws ecr create-repository --repository-name frontend
aws ecr create-repository --repository-name backendリポジトリのURIを取得する。
frontend_repo=$(aws ecr describe-repositories --repository-names frontend --query 'repositories[0].repositoryUri' --output text)
backend_repo=$(aws ecr describe-repositories --repository-names backend --query 'repositories[0].repositoryUri' --output text)タグ付けする。
docker tag frontend:latest ${frontend_repo}:latest
docker tag backend:latest ${backend_repo}:latestリモートにpushする。
# $(aws ecr get-login --no-include-email)
# aws ecr get-login-password | docker login --username AWS --password-stdin https://${frontend_repo%%/*}
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
AWS_REGION="ap-northeast-1"
aws ecr get-login-password | docker login --username AWS --password-stdin https://${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
docker push ${frontend_repo}
docker push ${backend_repo}Node.jsのインストールについては省略。
CDKをインストールする。
npm install -g aws-cdkPythonのvirtualenvを作成し、必要なモジュールをインストールする。
python3 -m venv .env
source venv/bin/activate
pip install -r requirements.txtデプロイを実行する。
cdk deploy *StackCDKを更新する。
# バージョン確認
cdk --version
# アップデート有無のチェック
sudo npm install -g npm-check-updates
npx npm-check-updates -g aws-cdk
# CDKのアップデート
sudo npm install -g aws-cdk各言語のローカルパッケージを更新する。
source venv/bin/activate
pip list -o | sed -e '1,2d' | cut -f1 -d' ' | xargs pip install -U