🙆‍♀️

PythonでAWS開発環境を整える

2022/09/01に公開

VSCodeの設定

pre-commitを導入する

pre-commit公式

インストール

pip install pre-commit

設定ファイル作成

pre-commit sample-config > .pre-commit-config.yaml

git反映

pre-commit install

設定を記述

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v3.3.0
  hooks:
  - id: check-added-large-files
  - id: check-json
  - id: check-toml
  - id: check-xml
  - id: check-yaml
  - id: debug-statements
  - id: detect-aws-credentials
    args: [--allow-missing-credentials]
  - id: detect-private-key
  - id: end-of-file-fixer
  # - id: no-commit-to-branch   # to protect specific branches from direct checkins.
    # args: [--branch, master]
  - id: pretty-format-json
    args: [--autofix]
- repo: https://github.com/psf/black
  rev: stable
  hooks:
  - id: black
    language_version: python3
- repo: https://gitlab.com/pycqa/flake8
  rev: 3.8.1
  hooks:
  - id: flake8
    # max-line-length setting is the same as black
    # commit cannot be done when cyclomatic complexity is more than 10.
    args: [--max-line-length, "88", --ignore=E402, --max-complexity, "10", --max-expression-complexity=7, --max-cognitive-complexity=7]
    additional_dependencies: [flake8-bugbear, flake8-builtins, flake8-eradicate, pep8-naming, flake8-expression-complexity, flake8-cognitive-complexity]

poetryを導入する

参考動画
poetry公式

インストール

curl -sSL https://install.python-poetry.org | python3 -

パスを通す

インストール後に出力されるメッセージを読み解いて、パスを追加。

echo 'export PATH="**********/Library/Python/3.9/bin:$PATH"' >> ~/.zshrc

linterとformatter入れる

poetry add -D flake8 black

CDKを使う

Python開発環境シェルに入る

poetry shell

aws profileを確認しておく

cat ~/.aws/credentials

接続しておく。profileは先で確認しておく。defaultの環境を使うならオプションは不要

cdk bootstrap --profile ****

Cloudformation作成

cdk synth

リソースデプロイ

cdk deploy

Discussion

ログインするとコメントできます