主にプログラミング関連のメモ帳 ♪(✿╹ヮ╹)ノ
書いてあるコードは自己責任でご自由にどうぞ。記事本文の無断転載は禁止です。
2018/11/24
ブログネタ何か欲しいとつぶやいたら、「AWS CDK で何か書いて」とネタをもらったので、
AWS CDK でのデプロイを自動化しました。
自動化は正義です。
前提 :
GitHub に push したら、良い感じに cdk deploy
が走るよう CircleCI に設定します。
こんな感じ
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:7.10
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run:
name: Install aws-cli
command: |
sudo apt update
sudo apt install -y awscli
- run:
name: Build
command: |
yarn run build
- run:
name: Configure AWS region
command: |
aws configure set region ap-northeast-1
- deploy:
name: Deployment
command: |
yarn run cdk deploy
CircleCI の AWS Deployment の設定にアクセスキーなどを設定しておきます。
途中で aws-cli をインストール、設定しているのは、 CircleCI には region の設定がないため。
そのほかは、 Nuxt.js のデプロイとかと変わらないです。
ちなみに、 AMI で CloudFormation なんちゃらと文句言われたら、
このポリシー付けておくと良いと思います (必要最低限のポリシー)。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"cloudformation:CreateChangeSet",
"cloudformation:ExecuteChangeSet",
"cloudformation:DescribeStackEvents"
],
"Resource": "arn:aws:cloudformation:ap-northeast-1:ID:stack/NAME/*"
}
]
}
ではでは\\٩( 'ω' )و //