2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【AWS CDK】インフラ変更内容をGitHub ActionsでPRに自動コメントする

Posted at

前提

aws cdk v2
typescript

やりたいこと

aws cdkで構成したインフラ環境の変更点をprで確認したい

やりかた

github actionsのymlを作成して、起動条件をpull_requestにして
以下の処理を好きなステップに記載

# ~省略~
      - name: diff
        run: npm run cdk diff > diff.txt
        env:
          AWS_DEFAULT_REGION: 'ap-northeast-1'
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

      - name: Comment PR with CDK Diff
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const fs = require('fs');
            const diff = fs.readFileSync('./diff.txt', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `CDK Diff:\n\`\`\`shell\n${diff}\n\`\`\``
            });

んでprを作成すると動いてるのと比較してくれる。

スクリーンショット 2023-05-29 6.44.13.png

作成したものは以下から確認できます

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?